1 Aug 2012 01:02
Re: language spec. channel description problem
On Tue, 31 Jul 2012, simon.place@... wrote: > being new to go, and using channels, i read the lang spec. ( > http://golang.org/ref/spec#Channel_types) and was confused by this; > > chan<- float64 // can only be used to send float64s > <-chan int // can only be used to receive ints > > and what appeared to be an illogical arrow semantic, after some checks i > decided the arrows were right but the comments were wrong, so i reported it > but was told it was right!! > > does anyone else think the sense of these is reversed? No. They refer to the permitted actions on *this* end of the channel. Think of it this way. If you have a "chan<-", you can only send values to the channel. channel <- value If you have a "<-chan", you can only get values from the channel value = <-channel The type symbols match up with the usage permitted by the type. -- -- Scott Lawrence(Continue reading)
RSS Feed