Whoa! Do Python and Lisp really have LAMBDA ?

Karl A. Krueger kkrueger at example.edu
Mon Oct 27 17:02:20 CET 2003


In comp.lang.lisp Marco Antoniotti <marcoxa at cs.nyu.edu> wrote:
> Common Lisp does it right.
> 
> (mapcar (lambda (f) (funcall f 1))
>    (mapcar (lambda (i)
>               (lambda (x) (+ x i)))
>       (list 1 2 3)))
> 
> ... This is what the Haskell code eventually boild down to.
> 
> It is Python that apparently cannot do this.  But, in all fairness, 
> nowhere in Python there is a claim that lambda expressions are full fledged.

Python lambda isn't *that* limited.  It's just that the equivalent is
rather ugly by Python standards:

[f(1) for f in
    [(lambda i: lambda x: x + i)(y)
    	for y in [1, 2, 3]]]

This also works, but isn't any prettier:

map(lambda f: apply(f, (1,)),
    map(lambda i:
    	   lambda x: (x + i),
        [1, 2, 3]))

(Bleah.  All those colons and commas are giving me MPI flashbacks.)

-- 
Karl A. Krueger <kkrueger at example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews




More information about the Python-list mailing list