[Python-ideas] Thoughts on lambda expressions
Ethan Furman
ethan at stoneleaf.us
Wed Mar 2 20:26:04 EST 2016
Note: Whatever fancy stuff you are doing to your messages is totally
messing up trying to reply to you.
On 03/02/2016 04:19 PM, Abe Dillon wrote:
> Not only did you get the syntax wrong,
Ah, I see that I did. Oops.
> but the lambda version is also
> horrid which is exacerbated by the fact that it looks like your trying
> to give the function a name or otherwise store it which defeats whole
> purpose of a lambda.
If I was giving it a name I would use `def`. I am storing it, and that
is a very common use of lambdas (to be fair, I stole one line from a
multi-line dictionary definition).
> At that point just use 'def' and stop trying to use
> lambda where it is ill suited.
This is exactly where lambda is suited.
> the idea is from the recipe metaphor for a function:
>
> def <recipe>(<ingredients>):
> ...instructions to cook ingredients
>
> vs.
>
> (<make_something> from <ingredients>)
Huh. Well, it looks good like that, but the actual examples were quite
jarring to me.
> It's fair to quibble over the exact implementation (maybe use 'with'
> instead of 'from') but the main point of the syntax it to put the
> important bit (i.e.the expression) in front of the (usually) unimportant
> bit (i.e. the signature) and to swap out an esoteric word (lambda) with
> something that continues the readability emphasis of Python by using
Yeah, it would be better with `with`. But, really, I don't see it
happening -- the whole anonymous function thing is not encouraged, so
making it easier is not a goal.
I wonder if MacroPy[1] would let you try it out?
--
~Ethan~
[1] https://pypi.python.org/pypi/MacroPy
More information about the Python-ideas
mailing list