D2 full closure?

Walter Bright newshound1 at digitalmars.com
Tue Jul 15 12:06:47 PDT 2008


BCS wrote:
> 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 '&'?

No, they are never copied. The delegates should refer directly to the 
variable which, in the case of a closure, gets allocated on the heap 
rather than the stack frame.

> 
> 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?

It isn't. The behavior you expect *is* the current behavior. The 
particular const behavior is (I haven't delved into it) the compiler 
incorrectly deciding that a const variable wouldn't need to be put on 
the heap.



More information about the Digitalmars-d mailing list