From b50ed022f5d735ee341ebdf15a9a151f4b6e5494 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 1 Feb 2011 12:02:49 -0800 Subject: [PATCH] go spec: follow-up cleanups after communication operator changes These are syntactical changes to better reflect the communication operator's new status in the language. - sending to a channel is now done via a send statement - there is no binary communication operation anymore which leads to a reduction of the number of precedence levels from 6 to 5 (yeah!) - small semantic change: since a send operation is not part of the expression syntax anymore, a <- send operator is binding weaker than any other operator now - receiving from a channel is done as before via the unary receive expression - communication clauses in select statement now can contain send statements or receive expressions R=rsc, r, iant, ken2, gri1 CC=golang-dev https://golang.org/cl/3973051 --- doc/go_spec.html | 121 ++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 8707591f66b..718a724e33e 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ - +

-Except in a communications clause of a select statement, -sending or receiving from a nil channel causes a +Receiving from a nil channel causes a run-time panic.

@@ -3087,6 +3053,7 @@ need to be presented regarding send, receive, select, and goroutines.

---> +

Method expressions

@@ -3508,7 +3475,7 @@ Statement = FallthroughStmt | Block | IfStmt | SwitchStmt | SelectStmt | ForStmt | DeferStmt . -SimpleStmt = EmptyStmt | ExpressionStmt | IncDecStmt | Assignment | ShortVarDecl . +SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl . @@ -3543,7 +3510,7 @@ Error: log.Crash("error encountered")

Expression statements

-Function calls, method calls, and channel operations +Function calls, method calls, and receive operations can appear in statement context.

@@ -3553,11 +3520,44 @@ ExpressionStmt = Expression .
-f(x+y)
+h(x+y)
+f.Close()
 <-ch
 
+

Send statements

+ +

+A send statement sends a value on a channel. +The channel expression must be of channel type +and the type of the value must be assignable +to the channel's element type. +

+ +
+SendStmt = Channel "<-" Expression .
+Channel  = Expression .
+
+ +

+Both the channel and the value expression are evaluated before communication +begins. Communication blocks until the send can proceed, at which point the +value is transmitted on the channel. +A send on an unbuffered channel can proceed if a receiver is ready. +A send on a buffered channel can proceed if there is room in the buffer. +

+ +
+ch <- 3
+
+ +

+Sending to a nil channel causes a +run-time panic. +

+ +

IncDec statements

@@ -4076,18 +4076,19 @@ cases all referring to communication operations.

 SelectStmt = "select" "{" { CommClause } "}" .
 CommClause = CommCase ":" { Statement ";" } .
-CommCase = "case" ( SendExpr | RecvExpr) | "default" .
-SendExpr =  Expression "<-" Expression .
-RecvExpr =  [ Expression ( "=" | ":=" ) ] "<-" Expression .
+CommCase   = "case" ( SendStmt | RecvStmt ) | "default" .
+RecvStmt   = [ Expression ( "=" | ":=" ) ] RecvExpr .
+RecvExpr   = Expression .
 

-For all the send and receive expressions in the "select" +RecvExpr must be a receive operation. +For all the cases in the "select" statement, the channel expressions are evaluated in top-to-bottom order, along with -any expressions that appear on the right hand side of send expressions. +any expressions that appear on the right hand side of send statements. A channel may be nil, which is equivalent to that case not being present in the select statement @@ -4398,7 +4399,7 @@ sent values have been received, receive operations will return the zero value for the channel's type without blocking. After at least one such zero value has been