From 461dd9126c9b8dc6a04b99a878e7cf1e4e1d00ea Mon Sep 17 00:00:00 2001
From: Russ Cox
The interface of a type is the set of methods bound to it @@ -661,6 +663,119 @@ StringLit = string_lit { string_lit } . "Alea " /* The die */ `iacta est` /* is cast */ "." +
+An array is a numbered sequence of elements of a single +type, called the element type, which must be complete +(§Types). The number of elements is called the length and is never +negative. +
+ ++ArrayType = "[" ArrayLength "]" ElementType . +ArrayLength = Expression . +ElementType = CompleteType . ++ +
+The length is part of the array's type and must must be a constant
+expression (§Constant expressions) that evaluates to a non-negative
+integer value. The length of array a
can be discovered
+using the built-in function len(a)
, which is a
+compile-time constant. The elements can be indexed by integer
+indices 0 through the len(a)-1
(§Indexes).
+
+[32]byte +[2*N] struct { x, y int32 } +[1000]*float64 ++ +
+A slice is a reference to a contiguous segment of an array and
+contains a numbered sequence of elements from that array. A slice
+type denotes the set of all slices of arrays of its element type.
+A slice value may be nil
.
+
+SliceType = "[" "]" ElementType . ++ +
+Like arrays, slices are indexable and have a length. The length of a
+slice s
can be discovered by the built-in function
+len(s)
; unlike with arrays it may change during
+execution. The elements can be addressed by integer indices 0
+through len(s)-1
(§Indexes). The slice index of a
+given element may be less than the index of the same element in the
+underlying array.
+
+A slice, once initialized, is always associated with an underlying +array that holds its elements. A slice therfore shares storage +with its array and with other slices of the same array; by contrast, +distinct arrays always represent distinct storage. +
+
+The array underlying a slice may extend past the end of the slice.
+The capacity is a measure of that extent: it is the sum of
+the length of the slice and the length of the array beyond the slice;
+a slice of length up to that capacity can be created by `slicing' a new
+one from the original slice (§Slices).
+The capacity of a slice a
can be discovered using the
+built-in function
+
+cap(s) ++ +
+and the relationship between len()
and cap()
is:
+
+0 <= len(a) <= cap(a) ++ +
+The value of an uninitialized slice is nil
.
+The length and capacity of a nil
slice
+are 0. A new, initialized slice value for a given element type T
is
+made using the built-in function make
, which takes a slice type
+and parameters specifying the length and optionally the capacity:
+
+make([]T, length) +make([]T, length, capacity) ++ +
+The make()
call allocates a new, hidden array to which the returned
+slice value refers. That is, calling make
+
+make([]T, length, capacity) ++ +
+produces the same slice as allocating an array and slicing it, so these two examples +result in the same slice: +
+ ++make([]int, 50, 100) +new([100]int)[0:50] ++ +
@@ -671,7 +786,7 @@ must be unique and field types must be complete (§Types).
-StructType = "struct" [ "{" [ FieldDeclList ] "}" ] . +StructType = "struct" "{" [ FieldDeclList ] "}" . FieldDeclList = FieldDecl { ";" FieldDecl } [ ";" ] . FieldDecl = (IdentifierList CompleteType | [ "*" ] TypeName) [ Tag ] . Tag = StringLit . @@ -745,36 +860,6 @@ struct { }-
-An array is a numbered sequence of elements of a single -type, called the element type, which must be complete -(§Types). The number of elements is called the length and is never -negative. -
- --ArrayType = "[" ArrayLength "]" ElementType . -ArrayLength = Expression . -ElementType = CompleteType . -- -
-The length is part of the array's type and must must be a constant
-expression (§Constant expressions) that evaluates to a non-negative
-integer value. The length of array a
can be discovered
-using the built-in function len(a)
, which is a
-compile-time constant. The elements can be indexed by integer
-indices 0 through the len(a)-1
(§Indexes).
-
-[32]byte -[2*N] struct { x, y int32 } -[1000]*float64 --
@@ -851,7 +936,7 @@ An interface value may be nil
.
-InterfaceType = "interface" [ "{" [ MethodSpecList ] "}" ] . +InterfaceType = "interface" "{" [ MethodSpecList ] "}" . MethodSpecList = MethodSpec { ";" MethodSpec } [ ";" ] . MethodSpec = IdentifierList Signature | InterfaceTypeName . InterfaceTypeName = TypeName . @@ -941,89 +1026,6 @@ type File interface { }-
-A slice is a reference to a contiguous segment of an array and
-contains a numbered sequence of elements from that array. A slice
-type denotes the set of all slices of arrays of its element type.
-A slice value may be nil
.
-
-SliceType = "[" "]" ElementType . -- -
-Like arrays, slices are indexable and have a length. The length of a
-slice s
can be discovered by the built-in function
-len(s)
; unlike with arrays it may change during
-execution. The elements can be addressed by integer indices 0
-through len(s)-1
(§Indexes). The slice index of a
-given element may be less than the index of the same element in the
-underlying array.
-
-A slice, once initialized, is always associated with an underlying -array that holds its elements. A slice therfore shares storage -with its array and with other slices of the same array; by contrast, -distinct arrays always represent distinct storage. -
-
-The array underlying a slice may extend past the end of the slice.
-The capacity is a measure of that extent: it is the sum of
-the length of the slice and the length of the array beyond the slice;
-a slice of length up to that capacity can be created by `slicing' a new
-one from the original slice (§Slices).
-The capacity of a slice a
can be discovered using the
-built-in function
-
-cap(s) -- -
-and the relationship between len()
and cap()
is:
-
-0 <= len(a) <= cap(a) -- -
-The value of an uninitialized slice is nil
.
-The length and capacity of a nil
slice
-are 0. A new, initialized slice value for a given element type T
is
-made using the built-in function make
, which takes a slice type
-and parameters specifying the length and optionally the capacity:
-
-make([]T, length) -make([]T, length, capacity) -- -
-The make()
call allocates a new, hidden array to which the returned
-slice value refers. That is, calling make
-
-make([]T, length, capacity) -- -
-produces the same slice as allocating an array and slicing it, so these two examples -result in the same slice: -
- --make([]int, 50, 100) -new([100]int)[0:50] -- -
@@ -1208,20 +1210,24 @@ type (
-these types are equal +these types are equal:
T0 and T0 T0 and T1 T0 and []string -T2 and T3 T4 and T5 -T3 and struct { a int; int } +T3 and struct { a int; c int }
-and these types are identical
+T2
and T3
are not equal because
+they have different field names.
+
+These types are identical:
@@ -1548,7 +1554,7 @@ to a new type. TODO: what exactly is a "new type"?TypeDecl = "type" ( TypeSpec | "(" [ TypeSpecList ] ")" ) . TypeSpecList = TypeSpec { ";" TypeSpec } [ ";" ] . -TypeSpec = identifier Type . +TypeSpec = identifier ( Type | "struct" | "interface" ) .@@ -1559,9 +1565,11 @@ type ( Polar Point ) +type Comparable interface + type TreeNode struct { left, right *TreeNode; - value Point; + value *Comparable; } type Comparable interface { -- 2.48.1