diff options
author | Robert Griesemer <gri@golang.org> | 2018-11-12 11:25:58 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2018-11-13 00:42:32 +0000 |
commit | de578dcdd682182c69efc8f9328c9bba500192b0 (patch) | |
tree | 334a2dda8dcf5bba502c4a9a2a5a3889b6d7a6cb /doc/go_spec.html | |
parent | 7ebe35093dbac03f86f7471590a18bf4ddd4b29c (diff) | |
download | go-de578dcdd682182c69efc8f9328c9bba500192b0.tar.gz go-de578dcdd682182c69efc8f9328c9bba500192b0.zip |
spec: be clearer about definition of string length
Adjusted spec to explicitly define the string length as the
number of bytes of the string; the prose now matches the prose
for arrays. Made analogous change for slices.
Fixes #28736.
Change-Id: I47cab321c87de0a4c482f5466b819b2cc8993fd1
Reviewed-on: https://go-review.googlesource.com/c/149077
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'doc/go_spec.html')
-rw-r--r-- | doc/go_spec.html | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index cc2bada913..098a92551a 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ <!--{ "Title": "The Go Programming Language Specification", - "Subtitle": "Version of October 23, 2018", + "Subtitle": "Version of November 12, 2018", "Path": "/ref/spec" }--> @@ -823,6 +823,7 @@ particular architecture. <p> A <i>string type</i> represents the set of string values. A string value is a (possibly empty) sequence of bytes. +The number of bytes is called the length of the string and is never negative. Strings are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is <code>string</code>; @@ -830,7 +831,7 @@ it is a <a href="#Type_definitions">defined type</a>. </p> <p> -The length of a string <code>s</code> (its size in bytes) can be discovered using +The length of a string <code>s</code> can be discovered using the built-in function <a href="#Length_and_capacity"><code>len</code></a>. The length is a compile-time constant if the string is a constant. A string's bytes can be accessed by integer <a href="#Index_expressions">indices</a> @@ -846,8 +847,7 @@ string, <code>&s[i]</code> is invalid. <p> An array is a numbered sequence of elements of a single type, called the element type. -The number of elements is called the length and is never -negative. +The number of elements is called the length of the array and is never negative. </p> <pre class="ebnf"> @@ -883,6 +883,7 @@ multi-dimensional types. A slice is a descriptor for a contiguous segment of an <i>underlying array</i> and provides access to a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. +The number of elements is called the length of the slice and is never negative. The value of an uninitialized slice is <code>nil</code>. </p> @@ -891,8 +892,7 @@ SliceType = "[" "]" ElementType . </pre> <p> -Like arrays, slices are indexable and have a length. The length of a -slice <code>s</code> can be discovered by the built-in function +The length of a slice <code>s</code> can be discovered by the built-in function <a href="#Length_and_capacity"><code>len</code></a>; unlike with arrays it may change during execution. The elements can be addressed by integer <a href="#Index_expressions">indices</a> 0 through <code>len(s)-1</code>. The slice index of a |