Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
0976e34d
Commit
0976e34d
authored
Sep 03, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Composite literal syntax.
R=r DELTA=25 (14 added, 2 deleted, 9 changed) OCL=14750 CL=14753
parent
e1e53e35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
doc/go_spec.txt
doc/go_spec.txt
+22
-10
No files found.
doc/go_spec.txt
View file @
0976e34d
...
...
@@ -4,7 +4,7 @@ The Go Programming Language Specification (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson
----
(
August 29
, 2008)
(
September 3
, 2008)
This document is a semi-formal specification of the Go systems
...
...
@@ -438,11 +438,11 @@ The following identifiers are predeclared:
- the predeclared constants
true, false, nil
true, false,
iota,
nil
- the predeclared functions (note: this list is likely to change)
cap(), convert(), len(), new(), panic(), print(), ...
cap(), convert(), len(), new(), panic(), print(),
typeof(),
...
TODO(gri) We should think hard about reducing the alias type list to:
...
...
@@ -1116,16 +1116,23 @@ if omitted, the first two examples above can be abbreviated:
Composite Literals
----
CompositeLit = ...
Literals for composite data structures consist of the type of the value
followed by a parenthesized expression list. In appearance, they are a
conversion from expression list to composite value.
followed by a parenthesized expression list for array and structure literals,
or a list of expression pairs for map literals.
CompositeLit = LiteralType "(" [ ( ExpressionList | ExprPairList ) [ "," ] ] ")" .
LiteralType = TypeName | ArrayType | MapType | StructType .
ExprPairList = ExprPair { "," ExprPair } .
ExprPair = Expression ":" Expression .
If LiteralType is a TypeName, the denoted type must be an array, map, or
structure. The types of the expressions must match the respective key, element,
and field types of the literal type; there is no automatic type conversion.
Structure literals follow this form directly.
Given
Given
type Rat struct { num, den int };
type Num struct { r Rat
, f float,
s string };
type Num struct { r Rat
; f float;
s string };
we can write
...
...
@@ -1142,12 +1149,17 @@ if a specified size is less than the number of elements in the expression list.
Map literals are similar except the elements of the expression list are
key-value pairs separated by a colon:
m := map[string]int("good":
0, "bad":1, "indifferent":
7)
m := map[string]int("good":
0, "bad": 1, "indifferent":
7)
TODO: helper syntax for nested arrays etc? (avoids repeating types but
complicates the spec needlessly.)
TODO(gri): These are not conversions and we could use {} instead of () in
the syntax. This will make literals such as Foo(1, 2, 3) clearly stand
out from function calls.
Function Literals
----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment