Python's Lisp heritage

Brian Quinlan brian at sweetapp.com
Fri Apr 26 14:43:37 EDT 2002


Jacek wrote:
> No, as Paul said, they are used for "function calls". Admittedly, in
> mathematical expressions function call often coincide with
> sub-expressions, but it does depend on the sub-expression in
> question. Compare
> 
>    (+ 1 2 3 4 5 6 7 8 9 10)
> 
> with
> 
>    1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
> 
> Gosh, what a lot of typing I have to do in Python, compared to lisp.

Actually, in your own example, the lisp example requires more typing.
You disingenuously inserted unnecessary spaces in the Python example.
Allow me to fix that:

Lisp:   (+ 1 2 3 4 5 6 7 8 9 10)
Python: 1+2+3+4+5+6+7+8+9+10

You could also write it like:

>>> reduce(operator.add, (1,2,3,4,5,6,7,8,9,10))
55

Your example is not really interesting, except to show that lisp has a
multi-argument add function and Python doesn't. Implementing one, as I
demonstrated above, is a one liner e.g.

def add(*args): return reduce(operator.add, args)
add(1,2,3,4,5,6,7,8,9,10)

Cheers,
Brian






More information about the Python-list mailing list