Deferred expressions (was Re: Lambda as declarative idiom)

Nick Coghlan ncoghlan at iinet.net.au
Tue Jan 4 10:31:37 CET 2005


Steven Bethard wrote:
> Nick Coghlan: def-from syntax [4]
> (def f(a) + o(b) - o(c) from (a, b, c))
> (def x * x from (x))
> (def x from ())
> (def x.bar(*a, **k) from (*a, **k))
> ((def x(*a, **k) from ()) for x, a, k in funcs_and_args_list)

After a bit more musing, this is definitely my preferred syntax. I'd call it a 
'deferred expression' rather than an anonymous function, though. The name change 
may seem minor, but it changes the emphasis of the feature from how it's 
implemented to what it is useful for (i.e. deferring evaluation of an expression 
until call time).

It's also conducive to a clean no-argument syntax - simply make the 'from' claus 
optional when the argument list is empty.

'def' and 'from' are already keywords, so there shouldn't be any compatibility 
problems.

Michael Spencer's idea of using 'for' instead of 'from' was quite interesting, 
but the use of 'for' without a corresponding 'in' feels a bit misleading :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list