Colon-Equals (:=) inner scoping

731 views
Skip to first unread message

James Nurmi

unread,
Dec 9, 2010, 10:45:42 PM12/9/10
to golan...@googlegroups.com
Sorry if this has been brought up before, but I was unable to
successfully find a matching email;

After several months of fairly intensive toying with go, I've
identified something that I'm not convinced is an actual issue, and
wanted to ask others what they thought.

The gist of the issue is that inner loop (for) blocks behave
differently than one might expect w/r/t ':=' and the rest of the go
language in my experience.

Attached )sorry) is an example of 3 common implementations of a
trivial function using a (contrived, trivial) double-return function,
and a (commented out) "idealized" syntax.

Since what's happening is actually understandable, it doesn't seem to
be a bug; That said, it's not an easy-to-spot difference between
variances without a keen eye.

Any thoughts/opinions?

Cheers,

James

test.go

rh

unread,
Dec 9, 2010, 10:59:19 PM12/9/10
to golang-nuts

James Nurmi

unread,
Dec 9, 2010, 11:35:35 PM12/9/10
to rh, golang-nuts
I do indeed, and feel enlightened by your quick pointer;

Rather than rehash that recent thread, I'll simply vote +1 for :=
'remasking' behavior to be consistent between for-loops and 'normal'
scope (completely ignoring inner functions and their concerns with
this vote). Of course, this isn't a democracy, so it's more a request
for touch-up paint on the shed I guess.

Thank you!

James

Mateusz Czapliński

unread,
Dec 10, 2010, 5:40:53 AM12/10/10
to golang-nuts
On Dec 10, 5:35 am, James Nurmi <jdnu...@qwe.cc> wrote:
> I do indeed, and feel enlightened by your quick pointer;
>
> Rather than rehash that recent thread, I'll simply vote +1 for :=
> 'remasking' behavior to be consistent between for-loops and 'normal'
> scope (completely ignoring inner functions and their concerns with
> this vote).  Of course, this isn't a democracy, so it's more a request
> for touch-up paint on the shed I guess.

Given the occasion, I'd like to ask the core dev team what's your
opinion on the proposals for explicitly marking/grouping the variables
on the left of =/:= which are meant to be reused vs. created anew? Was
maybe such an idea discussed earlier in Go development and discarded
because of something?

thanks in advance
Mateusz Czapliński

Mateusz Czapliński

unread,
Dec 10, 2010, 9:27:04 AM12/10/10
to golang-nuts
On Dec 10, 2:22 pm, Gustavo Niemeyer <gust...@niemeyer.net> wrote:
> And if you're *seriously* interested:
> [...]

Ah, great, thanks! Then I see a partial answer by one of the devs to
my last question was written on the 'golang-dev' list at:
http://groups.google.com/group/golang-dev/browse_thread/thread/37e72d4d4fc5a356

Then I suppose what I can do is to add a comment to issue 377 and
wait, hoping things get improved.
Thanks.

Mateusz Czapliński
Reply all
Reply to author
Forward
0 new messages