]> Cypherpunks repositories - gostls13.git/commitdiff
- clarification of type of array literals (always fixed array)
authorRobert Griesemer <gri@golang.org>
Wed, 3 Sep 2008 23:41:31 +0000 (16:41 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 3 Sep 2008 23:41:31 +0000 (16:41 -0700)
- clarification of const decl syntax

R=r
DELTA=9  (4 added, 0 deleted, 5 changed)
OCL=14771
CL=14771

doc/go_spec.txt

index e60fafa6d944bac38a24242caae2b650b4518b47..435263d1f07d8f7266036425561507df33937c42 100644 (file)
@@ -459,8 +459,9 @@ Const declarations
 A constant declaration gives a name to the value of a constant expression.
 
        ConstDecl = "const" ( ConstSpec | "(" ConstSpecList [ ";" ] ")" ).
-       ConstSpec = identifier [ Type ] [ "=" Expression ] .
-       ConstSpecList = ConstSpec { ";" ConstSpec }.
+       ConstSpec = identifier [ Type ] "=" Expression .
+       ConstSpecList = ConstSpec { ";" ConstSpecOptExpr }.
+       ConstSpecOptExpr = identifier [ Type ] [ "=" Expression ] .
 
        const pi float = 3.14159265
        const e = 2.718281828
@@ -1140,10 +1141,12 @@ we can write
 
        pi := Num(Rat(22,7), 3.14159, "pi")
 
-For array literals, if the size is present the constructed array has that many
+For array literals, if the length is present the constructed array has that many
 elements; trailing elements are given the approprate zero value for that type.
-If it is absent, the size of the array is the number of elements. It is an error
-if a specified size is less than the number of elements in the expression list.
+If it is absent, the length of the array is the number of elements. It is an error
+if the specified length is less than the number of elements in the expression list.
+In either case, the length is known at compile type and thus the type of an
+array literal is always a fixed array type.
 
        primes := [6]int(2, 3, 5, 7, 9, 11)
        weekdays := []string("mon", "tue", "wed", "thu", "fri", "sat", "sun")