On Monday, December 10, 2012 2:48:12 PM UTC+2, Rui Maciel wrote:
Is there any way to submit suggestions for the language specification?
To what end? It's extremely clear how it works. When you're having doubts, you can alway employ simple tests.--
Each if, for, and switch statement is considered to be in its own implicit block.
The scope of a constant or variable identifier declared inside a function begins at the end of the ConstSpec or VarSpec (ShortVarDecl for short variable declarations) and ends at the end of the innermost containing block.
On Monday, December 10, 2012 2:22:56 PM UTC+2, Rui Maciel wrote:
In Go's specification, it is stated that the expression in Go's if
Does anyone know what's the scope of variables declared this way? And
is this info defined anywhere in the language specifications?
Obviously in the Go specs: http://golang.org/ref/specYou have there, a link in the definition: SimpleStmt.This will lead you to: SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDeclClick on ShortVarDecl and you'll get your answer:In some contexts such as the initializers forif
,for
, orswitch
statements, they can be used to declare local temporary variables
On Monday, December 10, 2012 5:18:58 PM UTC+2, chris dollin wrote:
Original question:
)) Does anyone know what's the scope of variables declared this way?
)) And is this info defined anywhere in the language specifications?
This question isn't answered by the text you display.
--
"[...]local temporary variables" looks like scope resolution to me.
http://golang.org/ref/spec#ShortVarDecl look like a "somewhere" in the language specs to me.
Also, earlier, I provided with a shorter explanation:"Those vars will be accessible in the if block and any following else blocks."Now, is there something here you don't agree with?
For any other takers, the tour specifies and clarifies this:
http://tour.golang.org/#22
Like
for
, theif
statement can start with a short statement to execute before the condition.Variables declared by the statement are only in scope until the end of the
if
.
--