|
1 | 1 | <!--{
|
2 | 2 | "Title": "The Go Programming Language Specification",
|
3 |
| - "Subtitle": "Version of June 14, 2022", |
| 3 | + "Subtitle": "Version of June 21, 2022", |
4 | 4 | "Path": "/ref/spec"
|
5 | 5 | }-->
|
6 | 6 |
|
@@ -1811,6 +1811,31 @@ <h3 id="Core_types">Core types</h3>
|
1811 | 1811 | interface{ <-chan int | chan<- int } // directional channels have different directions
|
1812 | 1812 | </pre>
|
1813 | 1813 |
|
| 1814 | +<p> |
| 1815 | +Some operations (<a href="#Slice_expressions">slice expressions</a>, |
| 1816 | +<a href="#Appending_and_copying_slices"><code>append</code> and <code>copy</code></a>) |
| 1817 | +rely on a slightly more loose form of core types which accept byte slices and strings. |
| 1818 | +Specifically, if there are exactly two types, <code>[]byte</code> and <code>string</code>, |
| 1819 | +which are the underlying types of all types in the type set of interface <code>T</code>, |
| 1820 | +the core type of <code>T</code> is called <code>bytestring</code>. |
| 1821 | +</p> |
| 1822 | + |
| 1823 | +<p> |
| 1824 | +Examples of interfaces with <code>bytestring</code> core types: |
| 1825 | +</p> |
| 1826 | + |
| 1827 | +<pre> |
| 1828 | +interface{ int } // int (same as ordinary core type) |
| 1829 | +interface{ []byte | string } // bytestring |
| 1830 | +interface{ ~[]byte | myString } // bytestring |
| 1831 | +</pre> |
| 1832 | + |
| 1833 | +<p> |
| 1834 | +Note that <code>bytestring</code> is not a real type; it cannot be used to declare |
| 1835 | +variables are compose other types. It exists solely to describe the behavior of some |
| 1836 | +operations that read from a sequence of bytes, which may be a byte slice or a string. |
| 1837 | +</p> |
| 1838 | + |
1814 | 1839 | <h3 id="Type_identity">Type identity</h3>
|
1815 | 1840 |
|
1816 | 1841 | <p>
|
@@ -3837,7 +3862,8 @@ <h4>Simple slice expressions</h4>
|
3837 | 3862 |
|
3838 | 3863 | <p>
|
3839 | 3864 | constructs a substring or slice. The <a href="#Core_types">core type</a> of
|
3840 |
| -<code>a</code> must be a string, array, pointer to array, or slice. |
| 3865 | +<code>a</code> must be a string, array, pointer to array, slice, or a |
| 3866 | +<a href="#Core_types"><code>bytestring</code></a>. |
3841 | 3867 | The <i>indices</i> <code>low</code> and
|
3842 | 3868 | <code>high</code> select which elements of operand <code>a</code> appear
|
3843 | 3869 | in the result. The result has indices starting at 0 and length equal to
|
@@ -5469,7 +5495,7 @@ <h4 id="Conversions_to_and_from_a_string_type">Conversions to and from a string
|
5469 | 5495 |
|
5470 | 5496 | type myRune rune
|
5471 | 5497 | string([]myRune{0x266b, 0x266c}) // "\u266b\u266c" == "♫♬"
|
5472 |
| -myString([]myRune{0x1F30E}) // "\U0001f30e" == "🌎" |
| 5498 | +myString([]myRune{0x1f30e}) // "\U0001f30e" == "🌎" |
5473 | 5499 | </pre>
|
5474 | 5500 | </li>
|
5475 | 5501 |
|
@@ -7197,8 +7223,9 @@ <h3 id="Appending_and_copying_slices">Appending to and copying slices</h3>
|
7197 | 7223 | and the respective <a href="#Passing_arguments_to_..._parameters">parameter
|
7198 | 7224 | passing rules</a> apply.
|
7199 | 7225 | As a special case, if the core type of <code>s</code> is <code>[]byte</code>,
|
7200 |
| -<code>append</code> also accepts a second argument with core type <code>string</code> |
7201 |
| -followed by <code>...</code>. This form appends the bytes of the string. |
| 7226 | +<code>append</code> also accepts a second argument with core type |
| 7227 | +<a href="#Core_types"><code>bytestring</code></a> followed by <code>...</code>. |
| 7228 | +This form appends the bytes of the byte slice or string. |
7202 | 7229 | </p>
|
7203 | 7230 |
|
7204 | 7231 | <pre class="grammar">
|
@@ -7235,8 +7262,9 @@ <h3 id="Appending_and_copying_slices">Appending to and copying slices</h3>
|
7235 | 7262 | The number of elements copied is the minimum of
|
7236 | 7263 | <code>len(src)</code> and <code>len(dst)</code>.
|
7237 | 7264 | As a special case, if the destination's core type is <code>[]byte</code>,
|
7238 |
| -<code>copy</code> also accepts a source argument with core type <code>string</code>. |
7239 |
| -This form copies the bytes from the string into the byte slice. |
| 7265 | +<code>copy</code> also accepts a source argument with core type |
| 7266 | +</a> <a href="#Core_types"><code>bytestring</code></a>. |
| 7267 | +This form copies the bytes from the byte slice or string into the byte slice. |
7240 | 7268 | </p>
|
7241 | 7269 |
|
7242 | 7270 | <pre class="grammar">
|
@@ -7550,7 +7578,7 @@ <h3 id="Import_declarations">Import declarations</h3>
|
7550 | 7578 | </p>
|
7551 | 7579 |
|
7552 | 7580 | <p>
|
7553 |
| -Assume we have compiled a package containing the package clause |
| 7581 | +Consider a compiled a package containing the package clause |
7554 | 7582 | <code>package math</code>, which exports function <code>Sin</code>, and
|
7555 | 7583 | installed the compiled package in the file identified by
|
7556 | 7584 | <code>"lib/math"</code>.
|
|
0 commit comments