> 26 okt. 2016 kl. 22:19 skrev Chris Angelico <ros...@gmail.com>:
> 
> On Thu, Oct 27, 2016 at 7:12 AM, Martin Karlgren <ma...@roxen.com> wrote:
>>> 26 okt. 2016 kl. 21:23 skrev Chris Angelico <ros...@gmail.com>:
>>> 
>>>> On Thu, Oct 27, 2016 at 6:08 AM, Martin Karlgren <ma...@roxen.com> wrote:
>>>> A possible workaround is to cut the reference to the “foo” frame:
>>>> 
>>>> function f = lambda(string var1, string var2)
>>>>              {
>>>>                return lambda(string arg)
>>>>                       {
>>>>                         write("%O, %O, %O\n”, var1, var2, arg);
>>>>                       };
>>>>              }(var1, var2);
>>>> 
>>>> However, this is pretty verbose.
>>> 
>>> More significantly, this is *early binding* semantics. It captures the
>>> current values of var1 and var2, and won't notice any other changes.
>> 
>> Yep – don't know about other people but I don't think I've ever really 
>> wanted "late binding", so I think that's a good thing.
> 
> I have, often. It's also the same semantics as most other languages
> have for their closures. The most normal way to work with closures
> should be late-binding and writeable.

Alright. After looking at the syntax of a couple of other languages, though, it 
seems that [var1] is most often used for "by value" bindings and [&var1] for 
"by reference".

Possibly, the [&var1] syntax could be allowed in Pike too, to get the binding 
semantics of today's lambda but with explicit enumeration of captured variables 
(with compiler errors if other variables are referenced, otherwise it'd be 
useless). Cutting the reference to the frame (holding refs to all the other 
local variables) is probably a different story though.

/Marty

Reply via email to