Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
84c8d85f
Commit
84c8d85f
authored
Jul 23, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slices and string/array concatenation
OCL=13382 CL=13382
parent
f4dcf518
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
6 deletions
+44
-6
go_lang.txt
doc/go_lang.txt
+44
-6
No files found.
doc/go_lang.txt
View file @
84c8d85f
...
...
@@ -4,7 +4,7 @@ The Go Programming Language (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson
----
(July 2
1
, 2008)
(July 2
2
, 2008)
This document is a semi-formal specification/proposal for a new
systems programming language. The document is under active
...
...
@@ -1226,15 +1226,17 @@ Expression syntax is based on that of C but with fewer precedence levels.
PrimaryExpr =
identifier | Literal | "(" Expression ")" | "iota" |
Call | Conversion | Allocation |
Expression "[" Expression [ ":" Expression ] "]" | Expression "." identifier |
Expression "." "(" Type ")" .
Call | Conversion | Allocation | Index |
Expression "." identifier | Expression "." "(" Type ")" .
Call = Expression "(" [ ExpressionList ] ")" .
Conversion = "convert" "(" Type [ "," ExpressionList ] ")" |
ConversionType "(" [ ExpressionList ] ")" .
ConversionType = TypeName | ArrayType | MapType | StructType | InterfaceType .
Allocation = "new" "(" Type [ "," ExpressionList ] ")" .
Index = SimpleIndex | Slice .
SimpleIndex = Expression "[" Expression"]" .
Slice = Expression "[" Expression ":" Expression "]" .
binary_op = log_op | comm_op | rel_op | add_op | mul_op .
log_op = "||" | "&&" .
...
...
@@ -1497,6 +1499,42 @@ to acccess this conversion in low-level code but it will not be available
in general.
Slices and array concatenation
----
Strings and arrays can be ``sliced'' to construct substrings or subarrays.
The index expressions in the slice select which elements appear in the
result. The result has indexes starting at 0 and length equal to the difference
in the index values in the slice. After
a := []int(1,2,3,4)
slice := a[1:3]
The array ``slice'' has length two and elements
slice[0] == 2
slice[1] == 3
The index values in the slice must be in bounds for the original
array (or string) and the slice length must be non-negative.
Slices are new arrays (or strings) storing copies of the elements, so
changes to the elements of the slice do not affect the original.
In the example, a subsequent assignment to element 0,
slice[0] = 5
would have no effect on ``a''.
Strings and arrays can also be concatenated using the ``+'' (or ``+='')
operator.
a += []int(5, 6, 7)
s := "hi" + string(c)
Like slices, addition creates a new array or string by copying the
elements.
The constant generator 'iota'
----
...
...
@@ -2109,7 +2147,7 @@ followed by a series of declarations.
Program = PackageClause { ImportDecl [ ";" ] } { Declaration [ ";" ] } .
Initialization and
Program E
xecution
Initialization and
program e
xecution
----
A package with no imports is initialized by assigning initial values to
...
...
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