A replacement for lambda
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Jul 29 21:36:59 EDT 2005
Christopher Subich wrote:
> g = <x**2 with (x)>
> g(1) == 1
>
> Basically, I'd rewrite the Python grammar such that:
> lambda_form ::= "<" expression "with" parameter_list ">"
>
> Biggest change is that parameter_list is no longer optional, so
> zero-argument expr-comps would be written as <expr with ()>, which makes
> a bit more sense than <expr with>.
>
> Since "<" and ">" aren't ambiguous inside the "expression" state, this
> shouldn't make the grammar ambiguous. The "with" magic word does
> conflict with PEP-343 (semantically, not syntactically), so "for" might
> be appropriate if less precise in meaning.
What kind of shenanigans must a parser go through to translate:
<x**2 with(x)><<x**3 with(x)>
this is the comparison of two functions, but it looks like a left-
shift on a function until the second with is encountered. Then
you need to backtrack to the shift and convert it to a pair of
less-thans before you can successfully translate it.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list