Lambda as declarative idiom
Robert Brewer
fumanchu at amor.org
Tue Jan 4 17:31:17 EST 2005
Michael Spencer wrote:
> Roman Suzi wrote:
>
> > Maybe this is too outlandish, but I see lambdas as a
> "quote" mechanism,
> > which presents a possibility to postpone (precisely
> control, delegate)
> > evaluation. That is, an ovehead for lambda must be much
> lower but at the
> > same time visible to the programmer:
> >
> > d = a + (lambda x, y: x+ y)(3, 4)
> [...]
>
> I believe that this "possibility to postpone" divides into
> two related but separate concepts: controlling the moment
> of evaluation, and assembling the arguments required at
> that moment. They are both species of 'eval', but
> managing arguments is more specialized, because it includes
> possibly renaming parameters, assigning default values,
> processing positional and keyword arguments, and, perhaps
> in the future dealing with argument types.
Yes, but the "moment of evaluation" is more complex than just
"postponing". In a declarative construct, you probably also want global
variables to be bound early, so that the expression does not depend upon
*any* free variables. Ditto for closures. A more realistic example:
term = input("Enter the amount to add")
e = expr(x): x + term
...MUCH code passes, maybe even a new process or thread...
d = a + e(3)
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list