Why is Python popular, while Lisp and Scheme aren't?

Alex Martelli aleax at aleax.it
Thu Nov 21 06:31:11 EST 2002


Patrick W wrote:

> Alexander Schmolck <a.schmolck at gmx.net> writes:
> 
>> 2. try to write something in 1-100 lines in CL that couldn't easier be
>>    written in e.g. python.
> 
> Lots of things are easier in CL.
> A simple example:
> 
> (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), in that the above code isn't 
any easier than:

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)

and of course this could be further simplified by not even defining that 
useless class 'thing'...;-).


Alex




More information about the Python-list mailing list