Thank you for the explanations, I understand it better now.
Etienne
On Wednesday, 11 October 2017 14:26:56 UTC+2, Marvin Renich wrote:
>
> * Marvin Renich > [171011 08:19]:
> > > >> > //func fibo2() func() (x int) {
> > ^
> >
> > Here, x is a placeholder name wit
17 17:08:49 UTC+2, Etienne Daspe wrote:
>
> Thank you for the answer :)
>
> Etienne
>
> On Tuesday, 10 October 2017 16:58:43 UTC+2, Ian Lance Taylor wrote:
>>
>> On Tue, Oct 10, 2017 at 7:22 AM, wrote:
>> >
>> > I'm trying to understand the
Thank you for the answer :)
Etienne
On Tuesday, 10 October 2017 16:58:43 UTC+2, Ian Lance Taylor wrote:
>
> On Tue, Oct 10, 2017 at 7:22 AM, >
> wrote:
> >
> > I'm trying to understand the scope of variables when using closures.
> > I wrote a simple program to compute fibonacci sequence with
) { x, y = y, x+y }()
return x
}
}
// fibo2 doesn't compile because x is undefined in the function returned.
//func fibo2() func() (x int) {
//y := 1
//return func() int {
//defer func() { x, y = y, x+y }()
// return x
//}
//}
Regards,
Etienne Daspe
--