Re: Closures versus objects
Pascal Costanza <[email protected]>
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 20 Feb 2007, at 04:58, Dave Roberts wrote: > On Sun, 2007-02-18 at 18:22 -0600, Paul F. Dietz wrote: >> Pascal Costanza wrote: >> >>> >>> On 16 Feb 2007, at 19:22, Gary King wrote: >>> >>>> If Lisp was re-written today, I'd guess that there would be >>>> more use >>>> of generic functions for things like length. Then we would have: >>>> >>>> (length "butter") ==> 6 >>>> (length #(1 2 3)) ==> 3 >>>> >>>> and so on... >>> >>> >>> That's basically what happened in Dylan. >> >> >> There's nothing that prevents LENGTH from being implemented as a >> generic >> function in a compliant common lisp. Programs that depend on it >> being >> generic will not be portable, however. > > Which brings up a good point. Given this observation, why wasn't > LENGTH > made a GF when CL was specified? Was CLOS such a late addition and > everybody was afraid of the possible performance impact? Surely, there > was not technical reason that it couldn't have been made generic, > as you > say; all old code would have continued working, no? > > Over the past couple years, I have really learned to appreciate > CLOS and > this is one of those examples where it seems like a good idea wasn't > taken far enough. 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." Pascal -- Pascal Costanza, mailto:[email protected], http://p-cos.net Vrije Universiteit Brussel, Programming Technology Lab Pleinlaan 2, B-1050 Brussel, Belgium