Content deleted Content added
Line 3:
How could one use a closure that's not a function definition?
This isn't right. In perl6 blocks will technically be closures, but thats pretty obscure stuff afaik. In perl5 blocks aren't closures. [[User:Demerphq|Demerphq]] 19:09, 7 April 2006 (UTC)
Regarding the "acts as an object" comment, I was thinking of a closure like this:
Line 15 ⟶ 17:
$g = counter(7);
</pre>
Line 65 ⟶ 67:
----
Re: typical implementation as "a set of values that record the values of the relevant variables in the function's lexical environment at the time of binding", this was not correct. A naive Lisp interpreter can implement a closure as a pair containing a pointer to the function and a pointer to the actual lexical environment (activation record) at the point of capture. There's no recording of values, or selection of relevant variables for capture. Wasteful and slow, but adequate. [[User:K.lee|k.lee]] 17:27, 24 Oct 2003 (UTC)
----
IMO a Perl example is well called for. The counter example IMO isn't bad. I took the liberty of updating it a touch style wise tho, the &$f() style is a bit archaic. And really I think there are a lot more people out there that can read Perl than can read ML, and k.lee's comments appear a bit uninformed, shift isnt the only way to access arguments in perl. Also, Perl is one of the few "popular" (non-academic maybe is better) languages that makes heavy use of closures, so i think an example of it would be well worth while. [[User:Demerphq|Demerphq]] 19:09, 7 April 2006 (UTC)
----
|