Generic (dynamically overloaded) procedures

A generic procedure is a collection of method procedures. (A "method procedure" is not the same as a Java method, but the terms are related.) You can call a generic procedure, which selects the "closest match" among the component method procedures: I.e. the most specific method procedure that is applicable given the actual arguments.

Warning: The current implementation of selecting the "best" method is not reliable if there is more than one method. It can select depending on argument count, and it can select between primitive Java methods. However, selecting between different Scheme procedures based on parameter types should be considered experimental. The main problem is we can’t determine the most specific method, so Kawa just tries the methods in order.

Procedure: make-procedure [keyword: value]... method...

Create a generic procedure given the specific methods. You can also specify property values for the result.

The keywords specify how the arguments are used. A method: keyword is optional and specifies that the following argument is a method. A name: keyword specifies the name of the resulting procedure, when used for printing. Unrecognized keywords are used to set the procedure properties of the result.

(define plus10 (make-procedure foo: 33 name: 'Plus10
                            method: (lambda (x y) (+ x y 10))
                            method: (lambda () 10)))