From: Eric Schulte Date: 2008-10-16T10:58:00+09:00 Subject: Re: Sample for Metaprogramming Chad Perrin writes: > On Thu, Oct 16, 2008 at 04:53:04AM +0900, Sebastian Hungerecker wrote: >> Chad Perrin wrote: >> > I'm aware of the existence of CLOS, but don't really know anything about >> > its specifics of implementation and use.  How does it handle the kind of >> > functionality that, in Ruby, consists of sending messages to objects to >> > invoke their methods? >> >> It doesn't, really. CLOS methods are overloadable functions basically, i.e. >> you can define multiple methods of the same name, but with different argument >> types, and it'll pick the right one to call depending on the type(s) of the >> object(s) you pass as arguments. There's no concept of a receiver though. > > So, basically, instead of real methods, CLOS just uses . . . what? > Parametric polymorphism? This isn't meant as a challenge or complaint, > but rather just a question so I'll understand it better: > The following begins with a good overview of the rational behind the use of generic functions in CLOS instead of using a message passing system as used in ruby. http://www.dreamsongs.com/Files/ECOOP.pdf linked to from http://www.dreamsongs.com/CLOS.html It makes the good point that generic functions are a natural solution in any lisp. The paper states... | Furthermore, in Common Lisp, arithmetic operators are already | generic in a certain sense. The expression | | (+ x y) | | does not imply that x and y are of any particular type, nor does it | imply that they are of the same type. For example, x might be an | integer and y a complex number, and the + operation is required to | perform the correct coercions and produce an appropriate result. | | Because the Object System is a system for Common Lisp, it is | important that generic functions be first-class objects and that the | concept of generic functions be an extension and a generalization of | the concept of Common Lisp functions. In this way, the Object System | is a natural and smooth extension of Common Lisp. Also, CLOS contains mechanisms for implementing a message-passing based object system. Again from the paper... | Despite the advantages of generic functions, there may at times be | reasons for preferring a message-passing style; such a style can be | implemented by means of generic functions or by means of the Common | Lisp Object System Meta-Object Protocol. I would very much like to see any implementation of a ruby-like message based object system using CLOS. > > What about CLOS makes it "object oriented"? > The fact that it provides for the creation of objects which are instances of classes, and provides for inheritance between classes. :) -- Eric