Deferred expressions (was Re: Lambda as declarative idiom)
bokr at oz.net
Wed Jan 5 15:07:43 EST 2005
On Tue, 04 Jan 2005 19:31:37 +1000, Nick Coghlan <ncoghlan at iinet.net.au> wrote:
>Steven Bethard wrote:
>> Nick Coghlan: def-from syntax 
>> (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).
I like the fact that 'def' can serve as a mnemonic for 'defer' or 'deferred' ;-)
OTOH, I like concise notation for expressions, and the def and from aren't
really necessary if you can tag the first expression with some syntax marker.
I suggested (: rather than (def since (: is illegal now and won't break anything.
But all this is just a rewrite of lambda params:expr as (def expr from params).
What is the point again? (Not that my rewrite to (:expr)(params) is any more
than a lambda rewrite either). If backticks could be used, `(expr:params)
might be an interesting spelling of lambda params:expr.
I do like being able to leave out the from clause. `(expr) would let you do that too,
just as well as (:expr).
>It's also conducive to a clean no-argument syntax - simply make the 'from' claus
>optional when the argument list is empty.
That is an advantage of having it inside the outer parens, which my (:expr)(params)
couldn't benefit from -- unless I just take your format and substitute ':' for
both def and from:
(: f(a) + o(b) - o(c) : (a, b, c))
(: x * x : (x))
(: x) # empty arg list
(: x.bar(*a, **k) : (*a, **k))
((: x(*a, **k) : (x=x, a=a, k=k) for x, a, k in funcs_and_args_list)
>'def' and 'from' are already keywords, so there shouldn't be any compatibility
>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 :)
What was the point of all this again? Pretending lambda goes away without really killing it? ;-)
More information about the Python-list