LEFT | RIGHT |
1 <!--{ | 1 <!--{ |
2 "Title": "The Go Programming Language Specification", | 2 "Title": "The Go Programming Language Specification", |
3 » "Subtitle": "Version of August 3, 2012", | 3 » "Subtitle": "Version of August 9, 2012", |
4 "Path": "/ref/spec" | 4 "Path": "/ref/spec" |
5 }--> | 5 }--> |
6 | 6 |
7 <!-- | 7 <!-- |
8 TODO | 8 TODO |
9 [ ] need language about function/method calls and parameter passing rules | 9 [ ] need language about function/method calls and parameter passing rules |
10 [ ] last paragraph of #Assignments (constant promotion) should be elsewhere | 10 [ ] last paragraph of #Assignments (constant promotion) should be elsewhere |
11 and mention assignment to empty interface. | 11 and mention assignment to empty interface. |
12 [ ] need to say something about "scope" of selectors? | 12 [ ] need to say something about "scope" of selectors? |
13 [ ] clarify what a field name is in struct declarations | 13 [ ] clarify what a field name is in struct declarations |
(...skipping 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 Value = Expression | LiteralValue . | 2089 Value = Expression | LiteralValue . |
2090 </pre> | 2090 </pre> |
2091 | 2091 |
2092 <p> | 2092 <p> |
2093 The LiteralType must be a struct, array, slice, or map type | 2093 The LiteralType must be a struct, array, slice, or map type |
2094 (the grammar enforces this constraint except when the type is given | 2094 (the grammar enforces this constraint except when the type is given |
2095 as a TypeName). | 2095 as a TypeName). |
2096 The types of the expressions must be <a href="#Assignability">assignable</a> | 2096 The types of the expressions must be <a href="#Assignability">assignable</a> |
2097 to the respective field, element, and key types of the LiteralType; | 2097 to the respective field, element, and key types of the LiteralType; |
2098 there is no additional conversion. | 2098 there is no additional conversion. |
2099 The expressions in the element list are | |
2100 <a href="#Order_of_evaluation">evaluated in the usual order</a>. | |
2101 The key is interpreted as a field name for struct literals, | 2099 The key is interpreted as a field name for struct literals, |
2102 an index expression for array and slice literals, and a key for map literals. | 2100 an index expression for array and slice literals, and a key for map literals. |
2103 For map literals, all elements must have a key. It is an error | 2101 For map literals, all elements must have a key. It is an error |
2104 to specify multiple elements with the same field name or | 2102 to specify multiple elements with the same field name or |
2105 constant key value. | 2103 constant key value. |
2106 </p> | 2104 </p> |
2107 | 2105 |
2108 <p> | 2106 <p> |
2109 For struct literals the following rules apply: | 2107 For struct literals the following rules apply: |
2110 </p> | 2108 </p> |
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3689 TODO: perhaps ^ should be disallowed on non-uints instead of assuming twos compl
ement. | 3687 TODO: perhaps ^ should be disallowed on non-uints instead of assuming twos compl
ement. |
3690 Also it may be possible to make typed constants more like variables, at the cost
of fewer | 3688 Also it may be possible to make typed constants more like variables, at the cost
of fewer |
3691 overflow etc. errors being caught. | 3689 overflow etc. errors being caught. |
3692 </span> | 3690 </span> |
3693 </p> | 3691 </p> |
3694 --> | 3692 --> |
3695 | 3693 |
3696 <h3 id="Order_of_evaluation">Order of evaluation</h3> | 3694 <h3 id="Order_of_evaluation">Order of evaluation</h3> |
3697 | 3695 |
3698 <p> | 3696 <p> |
3699 Unless specified otherwise, when evaluating the <a href="#Operands">operands</a> | 3697 When evaluating the <a href="#Operands">operands</a> of an expression, |
3700 in an <a href="#Operators">expression</a>, expression list, | 3698 <a href="#Assignments">assignment</a>, or |
3701 or a <a href="#Composite_literals">composite literals</a> element list, | 3699 <a href="#Return_statements">return statement</a>, |
3702 all function calls, method calls and | 3700 all function calls, method calls, and |
3703 communication operations are evaluated in lexical left-to-right order. | 3701 communication operations are evaluated in lexical left-to-right |
| 3702 order. |
3704 </p> | 3703 </p> |
3705 | 3704 |
3706 <p> | 3705 <p> |
3707 For example, in the assignment | 3706 For example, in the assignment |
3708 </p> | 3707 </p> |
3709 <pre> | 3708 <pre> |
3710 y[f()], ok = g(h(), i()+x[j()], <-c), k() | 3709 y[f()], ok = g(h(), i()+x[j()], <-c), k() |
3711 </pre> | 3710 </pre> |
3712 <p> | 3711 <p> |
3713 the function calls and communication happen in the order | 3712 the function calls and communication happen in the order |
3714 <code>f()</code>, <code>h()</code>, <code>i()</code>, <code>j()</code>, | 3713 <code>f()</code>, <code>h()</code>, <code>i()</code>, <code>j()</code>, |
3715 <code><-c</code>, <code>g()</code>, and <code>k()</code>. | 3714 <code><-c</code>, <code>g()</code>, and <code>k()</code>. |
3716 However, the order of those events compared to the evaluation | 3715 However, the order of those events compared to the evaluation |
3717 and indexing of <code>x</code> and the evaluation | 3716 and indexing of <code>x</code> and the evaluation |
3718 of <code>y</code> is not specified. | 3717 of <code>y</code> is not specified. |
3719 </p> | 3718 </p> |
3720 | 3719 |
3721 <pre> | 3720 <pre> |
3722 a := 1 | 3721 a := 1 |
3723 f := func() int { a = 2; return 3 } | 3722 f := func() int { a = 2; return 3 } |
3724 x := []int{a, f()} // x may be [1, 3] or [2, 3] | 3723 x := []int{a, f()} // x may be [1, 3] or [2, 3]: evaluation order between a and
f() is not specified |
3725 </pre> | 3724 </pre> |
3726 | 3725 |
3727 <p> | 3726 <p> |
3728 Floating-point operations within a single expression are evaluated according to | 3727 Floating-point operations within a single expression are evaluated according to |
3729 the associativity of the operators. Explicit parentheses affect the evaluation | 3728 the associativity of the operators. Explicit parentheses affect the evaluation |
3730 by overriding the default associativity. | 3729 by overriding the default associativity. |
3731 In the expression <code>x + (y + z)</code> the addition <code>y + z</code> | 3730 In the expression <code>x + (y + z)</code> the addition <code>y + z</code> |
3732 is performed before adding <code>x</code>. | 3731 is performed before adding <code>x</code>. |
3733 </p> | 3732 </p> |
3734 | 3733 |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4493 <p> | 4492 <p> |
4494 There are three ways to return values from a function with a result | 4493 There are three ways to return values from a function with a result |
4495 type: | 4494 type: |
4496 </p> | 4495 </p> |
4497 | 4496 |
4498 <ol> | 4497 <ol> |
4499 <li>The return value or values may be explicitly listed | 4498 <li>The return value or values may be explicitly listed |
4500 in the "return" statement. Each expression must be single-valued | 4499 in the "return" statement. Each expression must be single-valued |
4501 and <a href="#Assignability">assignable</a> | 4500 and <a href="#Assignability">assignable</a> |
4502 to the corresponding element of the function's result type. | 4501 to the corresponding element of the function's result type. |
4503 The expressions are <a href="#Order_of_evaluation">evaluated in
the usual order</a>. | |
4504 <pre> | 4502 <pre> |
4505 func simpleF() int { | 4503 func simpleF() int { |
4506 return 2 | 4504 return 2 |
4507 } | 4505 } |
4508 | 4506 |
4509 func complexF1() (re float64, im float64) { | 4507 func complexF1() (re float64, im float64) { |
4510 return -7.0, -4.0 | 4508 return -7.0, -4.0 |
4511 } | 4509 } |
4512 </pre> | 4510 </pre> |
4513 </li> | 4511 </li> |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5531 </li> | 5529 </li> |
5532 | 5530 |
5533 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code>
is the same as | 5531 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code>
is the same as |
5534 <code>unsafe.Alignof(x[0])</code>, but at least 1. | 5532 <code>unsafe.Alignof(x[0])</code>, but at least 1. |
5535 </li> | 5533 </li> |
5536 </ol> | 5534 </ol> |
5537 | 5535 |
5538 <p> | 5536 <p> |
5539 A struct or array type has size zero if it contains no fields (or elements, resp
ectively) that have a size greater than zero. Two distinct zero-size variables m
ay have the same address in memory. | 5537 A struct or array type has size zero if it contains no fields (or elements, resp
ectively) that have a size greater than zero. Two distinct zero-size variables m
ay have the same address in memory. |
5540 </p> | 5538 </p> |
LEFT | RIGHT |