Thanks! 

Still it's the opposite of how a case works inside a switch statement. 

I understand these are different contexts but this difference is a bit of 
inconsistency and an unnecessary cognitive load (IMHO).

func main() {
 switch {
 case false && first() == 1:
 case true:
 log.Println("first not called")
 }


 // Output:
 // first not called
}


func first() int {
 defer log.Println("first called")
 return 1
}



On Sunday, December 31, 2017 at 11:21:57 AM UTC+3:30, Silviu Capota Mera 
wrote:
>
> Hi,
>
> I think your answer can be found in this section: 
> https://golang.org/ref/spec#SendStmt
>
> "Both the channel and the *value expression are evaluated* before 
> communication begins"
>
> cheers,
> silviu
>
> On Sunday, 31 December 2017 01:44:31 UTC-5, dc0d wrote:
>>
>> Assume there is this select statement:
>>
>> for {
>>     select {
>>     // ...
>>     // ...
>>
>>     case rcvd <- first():
>>     }
>> }
>>
>>
>> The rcvd channel will be set to nil or a chan value, by it's own case or 
>> other cases.
>>
>> If the rcvd channel is nil, that case should have no effect. But even 
>> when rcvd channel is nil, the first() function will be called.
>>
>> I did not expect that. Why is that so?
>>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to