Closure...https://play.golang.org/p/iBAh2V39MdE

https://play.golang.org/p/iBAh2V39MdE
This program is described by my teacher as " enclosing a variable in a block of code"
Are “a” and “b” the variables he’s talking about? Or is “x”?

https://play.golang.org/p/l099_Jwofjt

Is this closure?

You’ll need to ask them for clarification.

I do not see any extra block which would be there only to limit the scope of a variable. But this would be the thing I would have expected from this description your teacher gave you.

I can’t see one there… But to be honest, it looks as if this were actually the code fitting the questions from your first post… y is the variable that is limited in scope by an extra block.

And in the link you posted in your first post, there is a closure returned by incrementor().

1 Like

Ok, just did so.

https://play.golang.org/p/zAKB8Y0_JK2

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.