This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: multi-methods?
- From: Per Bothner <per at bothner dot com>
- To: Yaroslav Kavenchuk <kavenchuk at gmail dot com>
- Cc: kawa <kawa at sourceware dot org>
- Date: Tue, 25 Mar 2008 09:46:33 -0700
- Subject: Re: multi-methods?
- References: <47E802AC.1040108@bothner.com> <47E8B359.6080303@gmail.com>
Yaroslav Kavenchuk wrote:
Per Bothner wrote:
Read section "Procedures" in the manual, and specifically
look for 'define-procedure'.
I watched.
"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, it cannot yet do what you probably hope for: select between
different Scheme procedures based on parameter types."
Not sure how true that is now. I'll change the warning to say:
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.
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.
And simple double-dispatch is works:
(define-class Figure ())
(define-class Ball (Figure))
(define-procedure doSomething
(lambda ((ball :: Ball) (ball :: Ball)) :: void
(display "Ball-Ball\n"))
(lambda ((ball :: Ball) (fig :: Figure)) :: void
(display "Ball-Figure\n"))
(lambda ((fig :: Figure) (ball :: Ball)) :: void
(display "Figure-Ball\n"))
(lambda ((fig :: Figure) (fig :: Figure)) :: void
(display "Figure-Figure\n")))
(define ball :: Figure (Ball))
(define fig :: Figure (Figure))
(doSomething fig fig)
(doSomething fig ball)
(doSomething ball fig)
(doSomething ball ball)
But it is very dependent on the order of methods.
Yep.
--
--Per Bothner
per@bothner.com http://per.bothner.com/