merits of Lisp vs Python

hit_the_lights langstefan at gmx.at
Wed Dec 13 05:37:38 EST 2006


Paul Rubin schrieb:

> Neil Cerutti <horpner at yahoo.com> 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)".




More information about the Python-list mailing list