Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
fa538114
Commit
fa538114
authored
Oct 13, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spec: define order of multiple assignment
R=golang-dev, r, gri CC=golang-dev
https://golang.org/cl/5240055
parent
38fb09b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
go_spec.html
doc/go_spec.html
+23
-5
No files found.
doc/go_spec.html
View file @
fa538114
<!-- title The Go Programming Language Specification -->
<!-- title The Go Programming Language Specification -->
<!-- subtitle Version of
September 29
, 2011 -->
<!-- subtitle Version of
October 13
, 2011 -->
<!--
<!--
TODO
TODO
...
@@ -3730,14 +3730,32 @@ x, _ = f() // ignore second value returned by f()
...
@@ -3730,14 +3730,32 @@ x, _ = f() // ignore second value returned by f()
In the second form, the number of operands on the left must equal the number
In the second form, the number of operands on the left must equal the number
of expressions on the right, each of which must be single-valued, and the
of expressions on the right, each of which must be single-valued, and the
<i>
n
</i>
th expression on the right is assigned to the
<i>
n
</i>
th
<i>
n
</i>
th expression on the right is assigned to the
<i>
n
</i>
th
operand on the left.
operand on the left. The assignment proceeds in two phases.
The expressions on the right are evaluated before assigning to
First, the operands of
<a
href=
"#Indexes"
>
index expressions
</a>
any of the operands on the left, but otherwise the evaluation
and
<a
href=
"#Address_operators"
>
pointer indirections
</a>
order is unspecified beyond
<a
href=
"#Order_of_evaluation"
>
the usual rules
</a>
.
(including implicit pointer indirections in
<a
href=
"#Selectors"
>
selectors
</a>
)
on the left and the expressions on the right are all
<a
href=
"#Order_of_evaluation"
>
evaluated in the usual order
</a>
.
Second, the assignments are carried out in left-to-right order.
</p>
</p>
<pre>
<pre>
a, b = b, a // exchange a and b
a, b = b, a // exchange a and b
x := []int{1, 2, 3}
i := 0
i, x[i] = 1, 2 // set i = 1, x[0] = 2
i = 0
x[i], i = 2, 1 // set x[0] = 2, i = 1
x[0], x[0] = 1, 2 // set x[0] = 1, then x[0] = 2 (so x[0] = 2 at end)
x[1], x[3] = 4, 5 // set x[1] = 4, then panic setting x[3] = 5.
type Point struct { x, y int }
var p *Point
x[2], p.x = 6, 7 // set x[2] = 6, then panic setting p.x = 7
</pre>
</pre>
<p>
<p>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment