* jlforr...@berkeley.edu <jlforr...@berkeley.edu> [190329 15:28]:
> Thanks everyone for responding!
> 
> However, in the case that I illustrated there is no such problem. I
> would have thought that the language would allow this construct with
> any expression on the right side, as long as it only has one map
> access.
> 
> This isn't a big deal since it's so easy to work around, but it
> surprised me as a newcomer to Go.

I'm glad you got it figured out!  This may help you next time you run
into something similar:

Go is a strongly typed language, and its syntax consists of statements
and expressions.  Each expression only looks at its operands, and does
not depend on what complex sub-expression was evaluated to obtain
that operand.  Likewise, a statement only looks at the very outer layer
of its expressions.

So, for an assignment such as

  a, ok = foo(x[i]).y[z]

the compiler sees a potential assignment statement.  An assignment
statement must have a list of addressable expressions and/or map index
expressions on the left, which this does.  The expression on the right
must either be multi-valued, with two values, or it must be a map
indexing expression.  The only way this can be a map indexing expression
is if «foo(x[i]).y» evaluates to a map.

The Go syntax never looks deeper than this.  In fact, the Go
specification calls out this particular statement syntax as being a
"special form".  It only applies if the RHS _is_ a map indexing
expression, not if the RHS _contains_ a map indexing expression.

Hope this helps!

...Marvin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to