FAQ
The language specification - http://golang.org/ref/spec#Length_and_capacity
- says "The length and capacity of a nil slice, map, or channel are 0.".

However, it seems to work - http://play.golang.org/p/N-BtX758Hn (included
below for ease of read, too):

package main

import "fmt"

func main() {
c := make(chan int, 2)
fmt.Println("cap", cap(c))
fmt.Println("len", len(c))
c <- 1
c <- 2
fmt.Println("len", len(c))
fmt.Println(<-c)
fmt.Println(<-c)
fmt.Println("len", len(c))
}

So, which one here is it? :-)

1) I misunderstand the spec.
2) The spec is wrong.
3) The implementation is doing more than promised and it might go away.
4) Something I didn't think of.

This came up as a "sidebar" on
stackoverflow: http://stackoverflow.com/questions/15858658/do-go-channels-preserve-order-when-blocked


Ask

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Chris dollin at Apr 7, 2013 at 4:20 pm

    On 7 April 2013 17:14, wrote:

    The language specification -
    http://golang.org/ref/spec#Length_and_capacity - says "The length and
    capacity of a nil slice, map, or channel are 0.".

    However, it seems to work - http://play.golang.org/p/N-BtX758Hn (included
    below for ease of read, too):

    package main

    import "fmt"

    func main() {
    c := make(chan int, 2)
    fmt.Println("cap", cap(c))
    fmt.Println("len", len(c))
    c <- 1
    c <- 2
    fmt.Println("len", len(c))
    fmt.Println(<-c)
    fmt.Println(<-c)
    fmt.Println("len", len(c))
    }

    So, which one here is it? :-)

    1) I misunderstand the spec.
    Since your example has no nil channels in it, and your quote from
    the spec is about nil channels, that seems the plausible explanation.

    --
    Chris "allusive" Dollin

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ask Bjørn Hansen at Apr 7, 2013 at 4:56 pm

    On Apr 7, 2013, at 9:20, chris dollin wrote:


    1) I misunderstand the spec.
    Since your example has no nil channels in it, and your quote from
    the spec is about nil channels, that seems the plausible explanation.
    Indeed, I read it as:

    The length and capacity of a "nil slice", "map", or "channel" are 0

    Thank you!


    Ask

    --
    http://askask.com/

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 7, '13 at 4:14p
activeApr 7, '13 at 4:56p
posts3
users2
websitegolang.org

2 users in discussion

Ask Bjørn Hansen: 2 posts Chris dollin: 1 post

People

Translate

site design / logo © 2022 Grokbase