[Haskell-cafe] Lambda and closures in PHP -- could someone please
comment?
Richard A. O'Keefe
ok at cs.otago.ac.nz
Wed Jun 18 19:19:37 EDT 2008
On 18 Jun 2008, at 4:36 pm, Karoly Negyesi wrote:
>> (a) I would *never* want to use an implementation of closures like
>> that.
>> Could you elaborate on a) ?
It wasn't me who wrote it, but consider
- non-local variables are *not* captured unless you explicitly
hoist them into the lambda expression using the 'lexical' keyword.
- references to non-local variables that are not so hoisted are
not syntax errors, they just quietly do something else.
- ordinary functions do not act as if defined by lambda expressions;
'lexical' is required in lambdas and forbidden in functions.
- ordinary functions do not act as if defined by lambda expressions;
the latter can outlive their lexical scope, the former can't.
- what you get is a reference to a variable (as you do in Scheme)
but loop variables really are variables, not names for values,
so lambdas created in different iterations of the same loop point
so the same loop variable, and do not remember the value it had
when they were created. The proposal explains how to work around
this.
All of this boils down to something in which you *can* with care do
the things you expect to do with closures, but the language gently
leads you to the edge of the Pit and the compiler just smiles quietly
as you fall over.
More information about the Haskell-Cafe
mailing list