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


(Cherolyn Lexvold) #1

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


(Cherolyn Lexvold) #2

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

Is this closure?


(Norbert Melzer) #3

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().


(Cherolyn Lexvold) #4

Ok, just did so.


(Cherolyn Lexvold) #5

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