Paul Rubin schrieb: > Neil Cerutti <[EMAIL PROTECTED]> writes: > > Is the above 'duck-typing' idiom considered very useful to a > > Lisper? It seems logical to me that duck-typing works best in an > > environment where it is ubiquitous. If users have to implement > > accessors specifically to use your library, it is not as good as > > if they had already implemented one as a matter of routine.
No, it's not as ubiquitious as in Python. I guess that has many different reasons, probably many historical. IIRC Peter Seibel writes in Practical Common Lisp that CLOS (and thus "defgeneric") was introduced late in the CL standardization process. That my be one reason why it is not used extensively by the rest of the standardized language. > It's a little more complicated than that, the classes involved have to > have special interfaces to tell setf/getf what to do, sort of a > compile time equivalent of __setattr__/__getattr__ if I remember right. The code I've posted is all you need. You can specialize it for any class (including numbers, functions, symbols etc.) you like. In case of the lookup "($ a 0)" there is nothing done at compile time, it's just a call of the generic function "$". "(setf ($ a 0) 1)" is translated at compile time (setf is a macro) to something like "(funcall #'(setf $) 1 a 0)". -- http://mail.python.org/mailman/listinfo/python-list