The Go language specification on order of evaluation 
<https://golang.org/ref/spec#Order_of_evaluation> states:

  "when evaluating the operands of an expression, assignment, or return 
statement, all function calls, method calls, and communication operations 
are evaluated in lexical left-to-right order."

Consider the following program (also in the Go Playground 
<https://play.golang.org/p/o6O5nlN719n>):

  package main

  import (
      "fmt"
  )

  func modify(i *int) error {
      *i = 1
      return nil
  }

  func f() (int, error) {
      i := 0
      return i, modify(&i)
  }

  func main() {
      i, _ := f()
      fmt.Printf("i == %d\n", i)
  }

I would expect return value from f() to be 0, nil, as, evaluated left to 
right the operands have values 0 and nil, but instead the return value is 
1, nil.

What is the explanation for what's actually happening here? Can I rely on 
this behavior or might it change in future versions of Go?

Cheers,
Tom

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c257ce1c-49af-4a19-8bfd-601df759ffe1%40googlegroups.com.

Reply via email to