This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: multi-methods?
- From: Yaroslav Kavenchuk <kavenchuk at gmail dot com>
- Cc: kawa <kawa at sourceware dot org>
- Date: Thu, 27 Mar 2008 15:32:14 +0200
- Subject: Re: multi-methods?
- References: <47E92C69.4010501@bothner.com>
Per Bothner wrote:
> What is needed for for the compiler to emit a descriptor of
> the parameter types. The run-time already supports if: See
> the argTypes field of gnu.mapping.MethodProc.
>
> If you want to use multi-methods extensively, you might want
> to use the --full-tailcalls switch.
Bug with attempt to dispatch different arrays:
(define-procedure multi-dispatch
(lambda (x :: int[]) (display "This is array of int"))
(lambda (x :: String[]) (display "This is array of String"))
(lambda (x :: Object[]) (display "This is array of others")))
#|kawa:38|# (multi-dispatch (<int[]> 1 2 3 4 5))
This is array of int
#|kawa:39|# (multi-dispatch (String[]))
Argument #1 ([Ljava.lang.String;@1595f51) to 'lambda' has wrong type
([Ljava.lang.String;) ([Ljava.lang.String; cannot be cast to [I)
at atInteractiveLevel$23.apply(stdin:34)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:251)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:309)
at kawa.Shell.run(Shell.java:275)
at kawa.Shell.run(Shell.java:186)
at kawa.Shell.run(Shell.java:167)
at kawa.repl.main(repl.java:870)
Caused by: java.lang.ClassCastException: [Ljava.lang.String; cannot be
cast to [I
... 7 more
#|kawa:40|#
When delete first method:
(define-procedure multi-dispatch
(lambda (x :: String[]) (display "This is array of String"))
(lambda (x :: Object[]) (display "This is array of others")))
#|kawa:43|# (multi-dispatch (String[]))
This is array of String
#|kawa:44|# (multi-dispatch (integer[]))
Argument #1 ([Lgnu.math.IntNum;@6cb8) to 'lambda' has wrong type
([Lgnu.math.IntNum;) ([Lgnu.math.In
tNum; cannot be cast to [Ljava.lang.String;)
at atInteractiveLevel$26.apply(stdin:41)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:251)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:309)
at kawa.Shell.run(Shell.java:275)
at kawa.Shell.run(Shell.java:186)
at kawa.Shell.run(Shell.java:167)
at kawa.repl.main(repl.java:870)
Caused by: java.lang.ClassCastException: [Lgnu.math.IntNum; cannot be
cast to [Ljava.lang.String;
... 7 more
#|kawa:45|#
It can be fixed?
Thanks!
--
WBR, Yaroslav Kavenchuk.