Why is Python popular, while Lisp and Scheme aren't?
Patrick W
patrickw106 at yahoo.com.au
Thu Nov 21 08:55:02 EST 2002
Alex Martelli <aleax at aleax.it> writes:
> > (defclass thing () ())
> > (defclass paper (thing) ())
> > (defclass rock (thing) ())
> > (defclass scissors (thing) ())
> >
> > (defgeneric beats? (thing thing))
> > (defmethod beats? ((x thing) (y thing)) nil)
> > (defmethod beats? ((x paper) (y rock)) t)
> > (defmethod beats? ((x rock) (y scissors)) t)
> > (defmethod beats? ((x scissors) (y paper)) t)
>
> Multimethods are indeed very powerful, but it doesn't show "in the small"
> (quite typical for many very powerful things)
Right. I only intended to hint at a general concept that isn't widely
known outside of the Lisp and Dylan communities. It becomes *much*
harder to 'fake' multiple dispatch (multiple polymorphism?) in more
elaborate systems.
I think Lisp's multimethods are a decent example of how macros can
simplify a system in the long run. To graft support for multimethods
onto most languages would be major surgery -- but in Lisp it's just a
bunch of macros that extend Lisp in Lisp, leaving you with Lisp.
> class thing: pass
> class paper(thing): pass
> class rock(thing): pass
> class scissors(thing): pass
>
> def beats(x, y):
> def are(X,Y): return isinstance(x,X) and isinstance(y,Y)
> return are(paper,rock) or are(rock,scissors) or are(scissors,paper)
Nifty ;-)
More information about the Python-list
mailing list