LEFT | RIGHT |
1 <!--{ | 1 <!--{ |
2 "Title": "The Go Programming Language Specification", | 2 "Title": "The Go Programming Language Specification", |
3 » "Subtitle": "Version of October 23, 2012", | 3 » "Subtitle": "Version of November 1, 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 The following terms are used to denote specific Unicode character classes: | 111 The following terms are used to denote specific Unicode character classes: |
112 </p> | 112 </p> |
113 <pre class="ebnf"> | 113 <pre class="ebnf"> |
114 newline = /* the Unicode code point U+000A */ . | 114 newline = /* the Unicode code point U+000A */ . |
115 unicode_char = /* an arbitrary Unicode code point except newline */ . | 115 unicode_char = /* an arbitrary Unicode code point except newline */ . |
116 unicode_letter = /* a Unicode code point classified as "Letter" */ . | 116 unicode_letter = /* a Unicode code point classified as "Letter" */ . |
117 unicode_digit = /* a Unicode code point classified as "Decimal Digit" */ . | 117 unicode_digit = /* a Unicode code point classified as "Decimal Digit" */ . |
118 </pre> | 118 </pre> |
119 | 119 |
120 <p> | 120 <p> |
121 In <a href="http://www.unicode.org/versions/Unicode6.0.0/">The Unicode Standard
6.0</a>, | 121 In <a href="http://www.unicode.org/versions/Unicode6.2.0/">The Unicode Standard
6.2</a>, |
122 Section 4.5 "General Category" | 122 Section 4.5 "General Category" |
123 defines a set of character categories. Go treats | 123 defines a set of character categories. Go treats |
124 those characters in category Lu, Ll, Lt, Lm, or Lo as Unicode letters, | 124 those characters in category Lu, Ll, Lt, Lm, or Lo as Unicode letters, |
125 and those in category Nd as Unicode digits. | 125 and those in category Nd as Unicode digits. |
126 </p> | 126 </p> |
127 | 127 |
128 <h3 id="Letters_and_digits">Letters and digits</h3> | 128 <h3 id="Letters_and_digits">Letters and digits</h3> |
129 | 129 |
130 <p> | 130 <p> |
131 The underscore character <code>_</code> (U+005F) is considered a letter. | 131 The underscore character <code>_</code> (U+005F) is considered a letter. |
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 to specify multiple elements with the same field name or | 2121 to specify multiple elements with the same field name or |
2122 constant key value. | 2122 constant key value. |
2123 </p> | 2123 </p> |
2124 | 2124 |
2125 <p> | 2125 <p> |
2126 For struct literals the following rules apply: | 2126 For struct literals the following rules apply: |
2127 </p> | 2127 </p> |
2128 <ul> | 2128 <ul> |
2129 <li>A key must be a field name declared in the LiteralType. | 2129 <li>A key must be a field name declared in the LiteralType. |
2130 </li> | 2130 </li> |
2131 » <li>A literal that does not contain any keys must | 2131 » <li>An element list that does not contain any keys must |
2132 list an element for each struct field in the | 2132 list an element for each struct field in the |
2133 order in which the fields are declared. | 2133 order in which the fields are declared. |
2134 </li> | 2134 </li> |
2135 <li>If any element has a key, every element must have a key. | 2135 <li>If any element has a key, every element must have a key. |
2136 </li> | 2136 </li> |
2137 » <li>A literal that contains keys does not need to | 2137 » <li>An element list that contains keys does not need to |
2138 have an element for each struct field. Omitted fields | 2138 have an element for each struct field. Omitted fields |
2139 get the zero value for that field. | 2139 get the zero value for that field. |
2140 </li> | 2140 </li> |
2141 <li>A literal may omit the element list; such a literal evaluates | 2141 <li>A literal may omit the element list; such a literal evaluates |
2142 » » to the zero value for its type. | 2142 » to the zero value for its type. |
2143 </li> | 2143 </li> |
2144 <li>It is an error to specify an element for a non-exported | 2144 <li>It is an error to specify an element for a non-exported |
2145 field of a struct belonging to a different package. | 2145 field of a struct belonging to a different package. |
2146 </li> | 2146 </li> |
2147 </ul> | 2147 </ul> |
2148 | 2148 |
2149 <p> | 2149 <p> |
2150 Given the declarations | 2150 Given the declarations |
2151 </p> | 2151 </p> |
2152 <pre> | 2152 <pre> |
(...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4608 n = len(p) | 4608 n = len(p) |
4609 return | 4609 return |
4610 } | 4610 } |
4611 </pre> | 4611 </pre> |
4612 </li> | 4612 </li> |
4613 </ol> | 4613 </ol> |
4614 | 4614 |
4615 <p> | 4615 <p> |
4616 Regardless of how they are declared, all the result values are initialized to th
e zero | 4616 Regardless of how they are declared, all the result values are initialized to th
e zero |
4617 values for their type (§<a href="#The_zero_value">The zero value</a>) upon entry
to the | 4617 values for their type (§<a href="#The_zero_value">The zero value</a>) upon entry
to the |
4618 function, and they are set by the "return" statement before deferred functions a
re executed, | 4618 function. A "return" statement that specifies results sets the result parameters
before |
4619 if any. | 4619 any deferred functions are executed. |
4620 </p> | 4620 </p> |
4621 | 4621 |
4622 <!-- | 4622 <!-- |
4623 <p> | 4623 <p> |
4624 <span class="alert"> | 4624 <span class="alert"> |
4625 TODO: Define when return is required.<br /> | 4625 TODO: Define when return is required.<br /> |
4626 </span> | 4626 </span> |
4627 </p> | 4627 </p> |
4628 --> | 4628 --> |
4629 | 4629 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4738 </p> | 4738 </p> |
4739 | 4739 |
4740 <pre class="ebnf"> | 4740 <pre class="ebnf"> |
4741 FallthroughStmt = "fallthrough" . | 4741 FallthroughStmt = "fallthrough" . |
4742 </pre> | 4742 </pre> |
4743 | 4743 |
4744 | 4744 |
4745 <h3 id="Defer_statements">Defer statements</h3> | 4745 <h3 id="Defer_statements">Defer statements</h3> |
4746 | 4746 |
4747 <p> | 4747 <p> |
4748 A "defer" statement invokes a function whose execution is deferred to the moment
the surrounding | 4748 A "defer" statement invokes a function whose execution is deferred |
4749 function returns, either because the surrounding function executed a <a href="#R
eturn_statements">return statement</a>, | 4749 to the moment the surrounding function returns, either because the |
4750 reached the end of its <a href="#Function_declarations">function body</a>, or be
cause the corresponding goroutine is | 4750 surrounding function executed a <a href="#Return_statements">return statement</a
>, |
4751 <a href="#Handling_panics">panicking</a>. | 4751 reached the end of its <a href="#Function_declarations">function body</a>, |
| 4752 or because the corresponding goroutine is <a href="#Handling_panics">panicking</
a>. |
4752 </p> | 4753 </p> |
4753 | 4754 |
4754 <pre class="ebnf"> | 4755 <pre class="ebnf"> |
4755 DeferStmt = "defer" Expression . | 4756 DeferStmt = "defer" Expression . |
4756 </pre> | 4757 </pre> |
4757 | 4758 |
4758 <p> | 4759 <p> |
4759 The expression must be a function or method call. | 4760 The expression must be a function or method call. |
4760 Each time the "defer" statement | 4761 Each time the "defer" statement |
4761 executes, the function value and parameters to the call are | 4762 executes, the function value and parameters to the call are |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5614 </li> | 5615 </li> |
5615 | 5616 |
5616 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code>
is the same as | 5617 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code>
is the same as |
5617 <code>unsafe.Alignof(x[0])</code>, but at least 1. | 5618 <code>unsafe.Alignof(x[0])</code>, but at least 1. |
5618 </li> | 5619 </li> |
5619 </ol> | 5620 </ol> |
5620 | 5621 |
5621 <p> | 5622 <p> |
5622 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. | 5623 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. |
5623 </p> | 5624 </p> |
LEFT | RIGHT |