From: raja@... (Raja S.) Date: 2001-10-28T22:19:54+09:00 Subject: [ruby-talk:23678] Re: Ruby macros A Ruby macro system would indeed be interesting. When I used to code in Common Lisp and Scheme macros would be indispensible. Especially the convenience of Scheme's 'extend-syntax' and its more recent incarnation 'define-syntax'. Though a lot of the need for a macro system in Ruby is obviated by (a) we can define new methods on operators and (b) the presence of all the 'eval' methods. But using the 'eval' methods is as tricky / as not pretty as using CL's 'defmacro' and a more convenient interface along the lines of Scheme's 'define-syntax' would be great! About a decade ago, when Dylan first emerged it had a Lisp like s-expression systax. Shortly after it moved to a more conventional infix syntax. But it continued to have multi-methods and macros too. Born in the research labs of Apple (by Lisp gurus as David Moon), spending its childhood in the Gwydion project at CMU and the now defunct company, Harlequin, Dylan now seems to be getting a new life at Functional Objects: www.functionalobjects.com. It might be worth the while looking at the details of Dylans macro system and multi-methods to draw inspiration for a Ruby based one. Regards, Raja p.s. Avi Bryant writes: >The other issue, which I've only recently come across when playing with >Lisp, is that it's very hard to map a real message passing object model >onto generic functions. How do you do method_missing? And without >method_missing, how do you do, say, dRb? Unless you use some syntax like >(send 'foo obj) >which could be wrapped in a reader macro, leading to ugly constructs like >(if [foo obj] ... ), and preventing methods from being used as a lambda >anywhere. I'm curious to know what other problems you came across in tyring to map a message passing object model onto generic functions. While it has been a while since I coded in it, CLOS provides, 'no-applicable-method'. But this presumes that there is generic-function; its the method that is missing. If the generic-function itself is absent you may have to resort to the Lisp macro system: (defclass person () ((name :initarg :name :reader name) (yob :initarg :yob :reader yob))) (defmethod age ((p person)) (- 2001 (yob p))) (defmethod method-missing (msg (p person) &rest args) (format t "Don't know how to do ~s on ~s with ~s" msg p args)) (defmacro send (obj msg &rest args) `(if (fboundp ',msg) (,msg ,obj ,@args) (method-missing ',msg ,obj ,@args))) (setf p1 (make-instance 'person :name "joe" :yob 1975)) (send p1 age) (send p1 height) This would only handly top-level generic functions and not those defined with 'generic-flet' nor 'generic-labels'. But still the first-class hood of methods could be retained.