D2 full closure?
BCS
ao at pathlink.com
Tue Jul 15 11:57:37 PDT 2008
Reply to Walter,
> Frank Benoit wrote:
>
>> Is this output expected?
>>
> No, it's a bug. The output should be 0,1,2. Is it on bugzilla?
>
What?!! The value for the delegates are copied at the point of the '&'?
That seems more like currying to me.
In general I the behavior I would expect is that the values would never be
copied. I would expect that the outer function would store some of it's variable
on the heap and then all access (via delegate or in the outer function) would
be to the same values.
Why is the reverse preferable?
the proposed-to-be-correct behavior precludes having more than one delegate
operate on the same stuff or more generally, have side effects on the outer
function variables:
int delegate() DoIt()
{
int j = 10;
int i = 0
int B(){return i+=4;}
auto dg = &B;
while(j)
{
dg();
if(j & 0x01) i--;
}
return dg;
}
More information about the Digitalmars-d
mailing list