title: go method - pointer receiver and returning same pointer
body: <p>A go method on struct receives pointer reference, made some modifications and returning same pointer. The struct has nested reference of same struct: when append method being called with values some reason it was loosing previous values.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  type Node struct{
      next *Node
      val int
  }
  func newNode(val int) (*Node){
      n := Node{
      val: val,
      }
     return &amp;n
  }
  func (n *Node) append(val int) (*Node){
        for n.next != nil {
       n = n.next
        }
        n.next = newNode(val)
       return n
  }
  
  func (n *Node)printList(){
      for n != nil {
           fmt.Printf("%d,", n.val)
           n = n.next
      }
      fmt.Println()
  }
  
  
  func main() {
     n := newNode(3)
     n.printList()
     n = n.append(4)
     n.printList()
     n = n.append(5)
     n.printList()
     n = n.append(6)
     n.printList()    
  }
  </code></pre>
  
  <pre><code>output:
  3,
  3,4,
  4,5,
  5,6,
  </code></pre>
  
  <p>I was expecting 3,4,5,6, - Probably something I totally missing something fundamentals here. appreciate if you have some inputs.</p>
  
  <p><a href="https://play.golang.org/p/-zDH98UNFLa" rel="nofollow noreferrer">https://play.golang.org/p/-zDH98UNFLa</a></p>
  
  <p>I was getting expected results when I modify append method not return anything. </p>