"Christian" <christians / syd.microforte.com.au> writes:

> "Michael Schuerig" <schuerig / acm.org> wrote:
> 
> > It looks as if you're in need of multimethods such as are available in
> > Common Lisp and Dylan. Also, predicate classes and Cecil come to mind
> > (though only in a researchy mood).
> 
> Wow, you can't say that sort of thing without some references or
> explanation.
> 
> What is a multi-method? What is a predicate class? I sure am interested. I
> am passingly familiar with both Lisp and Dylan, and Cecil rings a bell but
> it is faint.
> 

C'mon Christian.  That's the second time you've said you're familiar
with Lisp.  But you don't know multi-methods?  I think you're kidding
us.  Common Lisp uses the CLOS which is based on generic functions.
The following is from _Ansi Common Lisp_, Paul Graham - which is a
beginner level text:

(defmethod combine (x y)
  (list x y))

; using it
; (combine 'a 'b)
; => (a b)

(defclass stuff () ((name :accessor name :initarg :name)))
(defclass ice-cream (stuff) ())
(defclass topping (stuff) ())

(defmethod combine ((ic ice-cream) (top topping))
  (format nil "~A ice-cream with ~A topping."
	  (name ic)
	  (name top)))

;;using the specialization
;(combine (make-instance 'ice-cream :name 'fig)
;	 (make-instance 'topping :name 'treacle))
; => "FIG ice-cream with TREACLE topping."

; without specialization
;(combine 'bruce 'sheila)
; => (bruce sheila)

The arguments determine the method to apply.
If none is applicable you get an error.  If there is one only, it gets
called, if more than one, the most specific gets called.

; and
(defmethod combine ((ic ice-cream) x)
	(format nil "~A ice-cream with ~A"
		(name ic)
		x))

;(combine (make-instance 'ice-cream :name mustard)
	'no-thanks)
; => "MUSTARD ice-cream with NO-THANKS"

You can also specialize methods on their types, so
(defmethod combine ((x number) (y number))
	(+ x y))
or individual objects.

Ruby uses the message passing model of OO.  Common Lisp uses generic
functions.  Methods are specialized for objects, and can be augmented.

Peter