Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
doc/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 -->
<!-- subtitle Version of
September 29
, 2011 -->
<!-- subtitle Version of
October 13
, 2011 -->
<!--
TODO
...
...
@@ -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
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
operand on the left.
The expressions on the right are evaluated before assigning to
any of the operands on the left, but otherwise the evaluation
order is unspecified beyond
<a
href=
"#Order_of_evaluation"
>
the usual rules
</a>
.
operand on the left. The assignment proceeds in two phases.
First, the operands of
<a
href=
"#Indexes"
>
index expressions
</a>
and
<a
href=
"#Address_operators"
>
pointer indirections
</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>
<pre>
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>
<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