This is the mail archive of the mailing list for the Kawa project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

generic procedures

Isn't the following supposed to work ?

(define f (make-procedure (lambda ((x :: <int>)) x)
                          (lambda ((x :: <string>)) x)))
(f 10) ;=> should return 10
(f "foo") ;=> should return "foo"

Instead of the expected results I get:
Argument  to `null' has wrong type
	at gnu.expr.GenericProc.applyN(
	at gnu.expr.ApplyExp.eval(
	at gnu.expr.ModuleExp.evalModule(
	at kawa.repl.main(

This is using the latest version of kawa from CVS.

Looking at the code, it appears that type-based matching is only done at
compile time and at run-time only the number of arguments are used as
the basis for finding a match. In cases like the above, type matching
needs to happen happen at both compile and run-time.

Also, it would be nice if the GenericProc.add method was exposed as a
scheme function/macro, so that one can "incrementally" add methods to a
generic proc, e.g.

(define f (make-procedure))
(add-method f (lambda ((x :: <int>)) x))
(add-method f (lamdda ((x :: <string>)) y))

I know I can achieve the same result by just calling the GenericProc.add
java method, but that feels like cheating :)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]