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
220edc48
Commit
220edc48
authored
Jul 22, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand section on compound literals.
R=ken,gri DELTA=31 (22 added, 0 deleted, 9 changed) OCL=13351 CL=13362
parent
c1f5eda7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
+27
-5
doc/go_lang.txt
doc/go_lang.txt
+27
-5
No files found.
doc/go_lang.txt
View file @
220edc48
...
...
@@ -678,15 +678,37 @@ structure.
}
Compo
und
Literals
Compo
site
Literals
----
Literals for compo
und data structures consist of the type of the constant
followed by a parenthesized expression list. In
effect
, they are a
conversion from expression list to compo
und
value.
Literals for compo
site 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 compo
site
value.
TODO: Needs to be updated.
Structure literals follow this form directly. Given
type Rat struct { num, den int };
type Num struct { r Rat, f float, s string };
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
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.
primes := [6]int(2, 3, 5, 7, 9, 11)
weekdays := []string("mon", "tue", "wed", "thu", "fri", "sat", "sun")
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)
TODO: helper syntax for nested arrays etc? (avoids repeating types but
complicates the spec needlessly.)
Pointer types
----
...
...
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