Re: Closures versus objects

Jacques Carette <[email protected]>
Newsgroups gmane.comp.lang.lightweight
Organization McMaster University
Message-ID <[email protected]>
Pascal Costanza wrote:
> Here is a quote from 
> http://groups.google.com/group/comp.lang.lisp/msg/3cad948789e116e9
>
> "The reason many operators are not generic [in Common Lisp] is that 
> deciding how to do
> them generically is tricky and people disagree on the definition. I
> recall the NIL project (JonL White, Jonathan Rees, and Rick Bryan) ran
> afoul of a generic definition for LENGTH enough that let us worry. 
> Consider:
>  (defmethod length ((x cons)) (+ 1 (length (cdr x))))
>  (defmethod length ((x null)) 0)
>  (defmethod length ((x string)) (array-dimension x 0))
> Now think about
>  (length '(a b . "foo"))
> The point is that often independent definitions invite what I'll call the
> "modularity problem" where definitions look ok in isolation but 
> surprising
> effects happen in combination.  Similar to what
>  (+ 1 2 "foo")
> might do if we allowed + to be generic."

And the end results of doing just that 'work' just fine.  Consider that 
Maple, Mathematica and MuPAD all have generic definitions of length and 
+, which are defined as in the above.

All those systems have a 1-level generic length function, and a 
fully-recursive generic length function, for the user to choose from.  + 
is done so that it adds up those pieces that are compatible, and returns 
the rest 'unevaluated'.  Actually, I am fairly sure that that is all 
really taken from Macsyma - which is Lisp par excellence!

Jacques
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.