FAQ
Reviewers: rsc, r, iant, ken2,

Message:
Hello rsc@golang.org, r@golang.org, iant@golang.org, ken@golang.org (cc:
golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go


Description:
spec: channel operations are restricted by the channel direction

Also:
- 'for' statements with a range clause do not accept send-only
channels
- '_, _ = range ch' is not equivalent to "_ = range ch" if ch
is a channel (rewriting the latter to the former leads to
an invalid range clause).

These clarifications document the status quo.

Please review this at https://codereview.appspot.com/6874053/

Affected files:
M doc/go_spec.html


Index: doc/go_spec.html
===================================================================
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of November 29, 2012",
+ "Subtitle": "Version of December 3, 2012",
"Path": "/ref/spec"
}-->

@@ -3249,8 +3249,9 @@
<p>
For an operand <code>ch</code> of <a href="#Channel_types">channel
type</a>,
the value of the receive operation <code>&lt;-ch</code> is the value
received
-from the channel <code>ch</code>. The type of the value is the element
type of
-the channel. The expression blocks until a value is available.
+from the channel <code>ch</code>. The channel direction must permit
receive operations,
+and the type of the receive operation is the element type of the channel.
+The expression blocks until a value is available.
Receiving from a <code>nil</code> channel blocks forever.
Receiving from a <a href="#Close">closed</a> channel always succeeds,
immediately returning the element type's <a href="#The_zero_value">zero
@@ -3873,8 +3874,9 @@

<p>
A send statement sends a value on a channel.
-The channel expression must be of <a href="#Channel_types">channel type</a>
-and the type of the value must be <a href="#Assignability">assignable</a>
+The channel expression must be of <a href="#Channel_types">channel
type</a>,
+the channel direction must permit send operations,
+and the type of the value to be sent must be <a
href="#Assignability">assignable</a>
to the channel's element type.
</p>

@@ -4319,12 +4321,13 @@

<p>
The expression on the right in the "range" clause is called the <i>range
expression</i>,
-which may be an array, pointer to an array, slice, string, map, or channel.
+which may be an array, pointer to an array, slice, string, map, or channel
permitting
+<a href="#Receive_operator">receive operations</a>.
As with an assignment, the operands on the left must be
<a href="#Address_operators">addressable</a> or map index expressions; they
denote the iteration variables. If the range expression is a channel, only
-one iteration variable is permitted, otherwise there may be one or two.
-If the second iteration variable is the <a href="#Blank_identifier">blank
identifier</a>,
+one iteration variable is permitted, otherwise there may be one or two. In
the latter case,
+if the second iteration variable is the <a href="#Blank_identifier">blank
identifier</a>,
the range clause is equivalent to the same clause with only the first
variable present.
</p>

@@ -4342,7 +4345,7 @@
array or slice a [n]E, *[n]E, or []E index i int a[i] E
string s string type index i int see below
rune
map m map[K]V key k K m[k] V
-channel c chan E element e E
+channel c chan E, <-chan E element e E
</pre>

<ol>

Search Discussions

  • Rsc at Dec 3, 2012 at 7:34 pm
    LGTM



    https://codereview.appspot.com/6874053/diff/4001/doc/go_spec.html
    File doc/go_spec.html (right):

    https://codereview.appspot.com/6874053/diff/4001/doc/go_spec.html#newcode3252
    doc/go_spec.html:3252: from the channel <code>ch</code>. The channel
    direction must permit receive operations,
    Link to direction definition?

    https://codereview.appspot.com/6874053/
  • Gri at Dec 3, 2012 at 9:43 pm
    Anybody else?
    - gri


    https://codereview.appspot.com/6874053/diff/4001/doc/go_spec.html
    File doc/go_spec.html (right):

    https://codereview.appspot.com/6874053/diff/4001/doc/go_spec.html#newcode3252
    doc/go_spec.html:3252: from the channel <code>ch</code>. The channel
    direction must permit receive operations,
    On 2012/12/03 19:34:35, rsc wrote:
    Link to direction definition?
    The definition is in the channel type section which is linked just
    before. Happy to add another link - but in general we haven't done this
    in the spec in other sections with similar situations.

    https://codereview.appspot.com/6874053/
  • Iant at Dec 3, 2012 at 10:18 pm
  • Gri at Dec 3, 2012 at 10:23 pm
    *** Submitted as
    https://code.google.com/p/go/source/detail?r=08462805eb2c ***

    spec: channel operations are restricted by the channel direction

    Also:
    - 'for' statements with a range clause do not accept send-only
    channels
    - '_, _ = range ch' is not equivalent to "_ = range ch" if ch
    is a channel (rewriting the latter to the former leads to
    an invalid range clause).

    These clarifications document the status quo.

    R=rsc, r, iant, ken
    CC=golang-dev
    https://codereview.appspot.com/6874053


    https://codereview.appspot.com/6874053/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 3, '12 at 7:28p
activeDec 3, '12 at 10:23p
posts5
users3
websitegolang.org

3 users in discussion

Gri: 3 posts Rsc: 1 post Iant: 1 post

People

Translate

site design / logo © 2022 Grokbase