Hi,
Is it possible to set a local variable from within a Closure?
I'd like to do something similar to :
Int wot := 0; [1,2,3].each |ever| { wot := wot + ever }
But I`m told Variable wot is already defined in current block.
Variable wot is already defined in current block
I understand the error, just don't know how to get around around it. I could use a for loop, I`d just rather not!
Steve.
You need to change := to = in your closure. := operator is used only for defining variable, = is use to reassign another value to it.
:=
=
defining
Hmm, okay. So I didn't get fundamental assignment operator:
Int wot := 0; [1,2,3].each |ever| { wot = wot + ever }
Now if only I could delete this thread and pretend I never posted it!
Thanks dluksza - I think our posts just crossed!
Login or Signup to reply.
SlimerDude Mon 30 Jan 2012
Hi,
Is it possible to set a local variable from within a Closure?
I'd like to do something similar to :
But I`m told
Variable wot is already defined in current block
.I understand the error, just don't know how to get around around it. I could use a for loop, I`d just rather not!
Steve.
dluksza Mon 30 Jan 2012
You need to change
:=
to=
in your closure.:=
operator is used only fordefining
variable,=
is use to reassign another value to it.SlimerDude Mon 30 Jan 2012
Hmm, okay. So I didn't get fundamental assignment operator:
Now if only I could delete this thread and pretend I never posted it!
SlimerDude Mon 30 Jan 2012
Thanks dluksza - I think our posts just crossed!