August 25, 2008 Re: Full closures | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote: > Reply to Bruno, > >> BCS wrote: >> >>> That is a good point, but how else you you get a real closure that >>> has mutable state? >>> >>> int delegate() Seq() >>> { >>> int at = 0; >>> int Next() { return at++; } >>> return &Next; >>> } >> Err.... just have a closure like D has now?... one that allows access >> to any visible variable? >> > > Franks local delegates won't work because they aren't valid after the other function returns, his heap delegates won't work because the variables they can access can't be altered. > > I feel there is a misunderstanding here. I wasn't talking about Frank's closures, but the one D currently has. What exactly did you mean with "how else [do] you get a real closure that has mutable state?" ? -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D | |||
August 25, 2008 Re: Full closures | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | Reply to Bruno,
> BCS wrote:
>
>> Reply to Bruno,
>>
>>> BCS wrote:
>>>
>>>> That is a good point, but how else you you get a real closure that
>>>> has mutable state?
>>>>
>>>> int delegate() Seq()
>>>> {
>>>> int at = 0;
>>>> int Next() { return at++; }
>>>> return &Next;
>>>> }
>>> Err.... just have a closure like D has now?... one that allows
>>> access to any visible variable?
>>>
>> Franks local delegates won't work because they aren't valid after the
>> other function returns, his heap delegates won't work because the
>> variables they can access can't be altered.
>>
> I feel there is a misunderstanding here. I wasn't talking about
> Frank's closures, but the one D currently has. What exactly did you
> mean with "how else [do] you get a real closure that has mutable
> state?" ?
>
The problem with the current ones is that they aren't valid in some cases if the outer function leave the scope the delegate is defined in.
void Foo()
{
int delegate() Bar;
for(int m = 3; m; m--)
{
const int i = m;
Ber = {return i;}
}
{
int j = 6;
int k = Bar();
//k could be 6
}
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply