title: Slices and multiple assignment in the Go Programming Language
body: <p>According to the <a href="https://golang.org/ref/spec#Assignments" rel="nofollow noreferrer">"Assignments" section</a> of the Go Language Spec:</p>
  
  <blockquote>
    <p>The assignment proceeds in two phases. First, the operands of index expressions and pointer indirections (including implicit pointer indirections in selectors) on the left and the expressions on the right are all evaluated in the usual order. Second, the assignments are carried out in left-to-right order.</p>
  </blockquote>
  
  <p>While playing with slices and attempting to implement a simple "delete" (or "splice") operation I see the following <a href="https://play.golang.org/p/112z6dVT4EP" rel="nofollow noreferrer">confusing behavior (Go Playground)</a>:</p>
  
  <pre><code>xs := []int{1, 2, 3, 4, 5}
  x := xs[2]
  xs = append(xs[:2], xs[3:]...)
  fmt.Printf("OK: x=%d, xs=%#v\n", x, xs)
  
  ys := []int{1, 2, 3, 4, 5}
  y, ys := ys[2], append(ys[:2], ys[3:]...)
  fmt.Printf("??: y=%d, ys=%#v\n", y, ys)
  
  // OK: x=3, xs=[]int{1, 2, 4, 5}
  // ??: y=4, ys=[]int{1, 2, 4, 5}
  </code></pre>
  
  <p>Why do the separate assignments to "x" and "xs" work as expected in the first example but the multi-assignment to "y" and "ys" appears to evaluate out of order? Is it related to the implicit define-and-assign combination?</p>