Skip to content

Commit de578dc

Browse files
committed
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 <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 7ebe350 commit de578dc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/go_spec.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of October 23, 2018",
3+
"Subtitle": "Version of November 12, 2018",
44
"Path": "/ref/spec"
55
}-->
66

@@ -823,14 +823,15 @@ <h3 id="String_types">String types</h3>
823823
<p>
824824
A <i>string type</i> represents the set of string values.
825825
A string value is a (possibly empty) sequence of bytes.
826+
The number of bytes is called the length of the string and is never negative.
826827
Strings are immutable: once created,
827828
it is impossible to change the contents of a string.
828829
The predeclared string type is <code>string</code>;
829830
it is a <a href="#Type_definitions">defined type</a>.
830831
</p>
831832

832833
<p>
833-
The length of a string <code>s</code> (its size in bytes) can be discovered using
834+
The length of a string <code>s</code> can be discovered using
834835
the built-in function <a href="#Length_and_capacity"><code>len</code></a>.
835836
The length is a compile-time constant if the string is a constant.
836837
A string's bytes can be accessed by integer <a href="#Index_expressions">indices</a>
@@ -846,8 +847,7 @@ <h3 id="Array_types">Array types</h3>
846847
<p>
847848
An array is a numbered sequence of elements of a single
848849
type, called the element type.
849-
The number of elements is called the length and is never
850-
negative.
850+
The number of elements is called the length of the array and is never negative.
851851
</p>
852852

853853
<pre class="ebnf">
@@ -883,6 +883,7 @@ <h3 id="Slice_types">Slice types</h3>
883883
A slice is a descriptor for a contiguous segment of an <i>underlying array</i> and
884884
provides access to a numbered sequence of elements from that array.
885885
A slice type denotes the set of all slices of arrays of its element type.
886+
The number of elements is called the length of the slice and is never negative.
886887
The value of an uninitialized slice is <code>nil</code>.
887888
</p>
888889

@@ -891,8 +892,7 @@ <h3 id="Slice_types">Slice types</h3>
891892
</pre>
892893

893894
<p>
894-
Like arrays, slices are indexable and have a length. The length of a
895-
slice <code>s</code> can be discovered by the built-in function
895+
The length of a slice <code>s</code> can be discovered by the built-in function
896896
<a href="#Length_and_capacity"><code>len</code></a>; unlike with arrays it may change during
897897
execution. The elements can be addressed by integer <a href="#Index_expressions">indices</a>
898898
0 through <code>len(s)-1</code>. The slice index of a

0 commit comments

Comments
 (0)