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>
- To: Per Bothner <per at bothner dot com>
- Cc: kawa <kawa at sourceware dot org>
- Date: Tue, 25 Mar 2008 10:10:01 +0200
- Subject: Re: multi-methods?
- References: <47E802AC.1040108@bothner.com>
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."
^^^^^^^^^^^^^^^^^^^^^^^^
That stopped me.
Some example of multi-methods using define-procedure are in
kawa/lib/numers.scm (in the SVN version).
Many thanks! It is work!
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.
Many thanks again!
--
WBR, Yaroslav Kavenchuk.