This is the mail archive of the kawa@sourceware.org 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]
Other format: [Raw text]

Re: multi-methods?


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.


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