From 164a7bceeb67af9490d970e3c6e665198c6e1c9a Mon Sep 17 00:00:00 2001
From: Robert Griesemer
-chan T // can be used to send and receive values of type T +chan T // can be used to send and receive values of type T chan<- float // can only be used to send floats <-chan int // can only be used to receive ints@@ -1121,12 +1118,8 @@ or absent, the communication succeeds only when both a sender and receiver are r
-For a channel c
, the predefined function close(c)
-marks the channel as unable to accept more
-values through a send operation. After any previously
-sent values have been received, receives will return
-the zero value for the channel's type. After at least one such zero value has been
-received, closed(c)
returns true.
+A channel may be closed and tested for closure with the built-in functions
+close
and closed
.
CompositeLit = LiteralType "{" [ ElementList ] "}" . LiteralType = StructType | ArrayType | "[" "..." "]" ElementType | - SliceType | MapType | TypeName . + SliceType | MapType | TypeName | "(" LiteralType ")" . ElementList = Element { "," Element } [ "," ] . Element = [ Key ":" ] Value . Key = FieldName | Index . @@ -2134,10 +2127,15 @@ as they are accessible.Primary expressions
++Primary expressions are the operands for unary and binary expressions. +
+PrimaryExpr = Operand | Conversion | + BuiltinCall | PrimaryExpr Selector | PrimaryExpr Index | PrimaryExpr Slice | @@ -3059,6 +3057,84 @@ It is legal to derive a function value from a method of an interface type. The resulting function takes an explicit receiver of that interface type. +Conversions
+ ++Conversions are expressions of the form
+ +T(x)
+whereT
is a type andx
is an expression +that can be converted to typeT
. ++Conversion = LiteralType "(" Expression ")" . ++ ++The following conversion rules apply: +
+
T
.
+T
if the value's type, or T
, or any of their component
+types were unnamed.
+x := uint16(0x10F0)
, then uint32(int8(x)) == 0xFFFFFFF0
.
+The conversion always yields a valid value; there is no indication of overflow.
++string(0x65e5) // "\u65e5" == "æ¥" == "\xe6\x97\xa5" ++ +
nil
, the result is the empty string.
++string([]int{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "ç½éµ¬ç¿"+
nil
,
+the result is the empty string.
+
++string([]byte{'h', 'e', 'l', 'l', 'o'}) // "hello" ++
+There is no linguistic mechanism to convert between pointers and integers.
+The package unsafe
+implements this functionality under
+restricted circumstances.
+
@@ -3978,136 +4054,62 @@ for i := 0; i <= 3; i++ { } -
-Call Argument type Result - -len(s) string string length (in bytes) - [n]T, *[n]T array length (== n) - []T slice length - map[K]T map length (number of defined keys) - chan T number of elements sent queued in channel buffer - -cap(s) [n]T, *[n]T array length (== n) - []T slice capacity - chan T channel buffer capacity -- -
-The type of the result is always int
and the
-implementation guarantees that
-the result always fits into an int
.
-The capacity of a slice or map is the number of elements for which there is
-space allocated in the underlying array (for a slice) or map. For a slice
-s
, at any time the following relationship holds:
+A small number of built-in functions are
+predeclared.
+They are called like any other function but some of them
+accept a type instead of an expression as the first argument.
+
-0 <= len(s) <= cap(s) ++BuiltinCall = identifier "(" [ BuiltinArgs ] ")" . +BuiltinArgs = Type [ "," ExpressionList ] | ExpressionList .- -Conversions
+Close and closed
-Conversions look like function calls of the form +For a channel
-c
, the predefined functionclose(c)
+marks the channel as unable to accept more +values through a send operation. After any previously +sent values have been received, receive operations will return +the zero value for the channel's type. After at least one such zero value has been +received,closed(c)
returns true.-T(value) -+Length and capacity
-where
-T
is a type -andvalue
is an expression -that can be converted to a value -of result typeT
. +The built-in functionslen
andcap
take arguments +of various types and return a result of typeint
. +The implementation guarantees that the result always fits into anint
.-Conversion = ( TypeName | "(" Type ")" ) Expression . -++Call Argument type Result --The following conversion rules apply: -
-
T
.
-T
if the value's type, or T
, or any of their component
-types were unnamed (§Type identity and compatibility).
-x := uint16(0x10F0)
, then uint32(int8(x)) == 0xFFFFFFF0
.
-The conversion always yields a valid value; there is no indication of overflow.
--string(0x65e5) // "\u65e5" == "æ¥" == "\xe6\x97\xa5" +cap(s) [n]T, *[n]T array length (== n) + []T slice capacity + chan T channel buffer capacity-
nil
, the result is the empty string.
--string([]int{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "ç½éµ¬ç¿"-
nil
,
-the result is the empty string.
++The capacity of a slice is the number of elements for which there is +space allocated in the underlying array. +At any time the following relationship holds: +
-string([]byte{'h', 'e', 'l', 'l', 'o'}) // "hello" +0 <= len(s) <= cap(s)-
-There is no linguistic mechanism to convert between pointers and integers.
-The package unsafe
-implements this functionality under
-restricted circumstances.
-
-TODO: Need syntax that permits a type as first argument for built-ins. +Current implementations provide several built-in functions useful during +bootstrapping. These functions are documented for completeness but are not +guaranteed to stay in the language. They do not return a result.
++Call Behavior + +print prints all arguments; formatting of arguments is implementation-specific +println like print but prints spaces between arguments and a newline at the end +panic like print, aborts execution after printing +panicln like println, aborts execution after printing ++ +
-- 2.48.1