Lambda going out of fashion
Nick Coghlan
ncoghlan at iinet.net.au
Thu Dec 23 08:32:50 EST 2004
Alex Martelli wrote:
> Nick Coghlan <ncoghlan at iinet.net.au> wrote:
> ...
>
>>Perhaps something like:
>>
>>accepts_func( (def (a, b, c) to f(a) + o(b) - o(c)) )
>
>
> Nice, except I think 'as' would be better than 'to'. 'as' should be a
> full keyword in 3.0 anyway (rather than a surprisingly-NOT-keyword like
> today), and "define something as somethingelse" seems marginally more
> readable to me than "define something to somethingelse" anyway.
I actually flipped back and forth between preferring 'as' and 'to' while writing
the message.
It was the mathematical phrasing of "f is a function from R to R" (replacing the
capital R's with the symbol for the real numbers) that first made me think of
'to', since I was trying to emphasise the parallels with mathematical functions.
(To my mind, theoretical mathematics is one of the areas with significant
legitimate uses for lambda functions).
The '->' suggestion had a similar source.
The way I'd read the 'to' version out loud when explaining to someone what the
code did:
"DEFine an anonymous function from arguments a, b and c TO the value f of a plus
o of b minus o of c"
or the short version:
"DEFine a function from a, b and c TO f a plus o b minus o c"
As an even simpler example, (def (x) to x * x) would be "define a function from
x to x squared". (def () to <whatever>) would be "define a function from no
arguments to <whatever>"
'as' already implies renaming semantics due to from-style imports. In Py3k, it's
likely to pick up the naming duties in except clauses as well (i.e. "except
ValueError, TypeError as ex:").
'as' is also a candidate for optional static typing and adaptation (and
hopefully someone will talk Guido out of his punctuation happy version of that!).
I eventually decided that using 'as' for anonymous functions as well would just
be plain confusing.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list