Re: Whoa! Do Python and Lisp really have LAMBDA ?

From: Karl A. Krueger (kkrueger_at_example.edu)
Date: 10/27/03


Date: Mon, 27 Oct 2003 16:02:20 +0000 (UTC)

In comp.lang.lisp Marco Antoniotti <marcoxa@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@example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews


Relevant Pages

  • Re: How to create functors?
    ... Lambda expressions are, I believe, syntactically limited to a single expression -- no statements, like 'print' is in Python 2.x. ... exact answer you need may vary. ... I want to avoid using a def if possible. ...
    (comp.lang.python)
  • Re: is python Object oriented??
    ... execute a piece of python code without defining class, ... python does not force you to lay out your code according to ... Now python does not have any way besides lambda expressions of creating ... polymorphism are implemented clumsily (actually I'm not even sure ...
    (comp.lang.python)
  • Re: Whoa! Do Python and Lisp really have LAMBDA ?
    ... This is what the Haskell code eventually boild down to. ... > nowhere in Python there is a claim that lambda expressions are full fledged. ...
    (comp.lang.python)
  • Re: is python Object oriented??
    ... execute a piece of python code without defining class, ... python does not force you to lay out your code according to ... Now python does not have any way besides lambda expressions of creating ...
    (comp.lang.python)