Skip to content

Instantly share code, notes, and snippets.

@goldeneggg
Last active June 17, 2020 13:43
Show Gist options
  • Save goldeneggg/119310436c7f873e8506705b6ba417cf to your computer and use it in GitHub Desktop.
Save goldeneggg/119310436c7f873e8506705b6ba417cf to your computer and use it in GitHub Desktop.
package main
import "fmt"
func Print(type T)(s []T) {
for _, v := range s {
fmt.Println(v)
}
}
func main() {
a := []int{1, 2, 3, 4, 5}
b := []float64{1.1, 2.2, 3.3, 4.4, 5.5}
Print(a)
Print(int)(a)
Print(b)
}
@goldeneggg
Copy link
Author

goldeneggg commented Jun 17, 2020

# setup for your machine

$ cd ~
$ git clone https://go.googlesource.com/go goroot

$ cd ~/goroot/src
$ git checkout dev.go2go
$ ./all.bash

$ export GOPATH=~/goroot
$ export GOROOT=~/goroot

$ vim hoge.go2
# write this gist contents
  package main

  import "fmt"

  func Print(type T)(s []T) {
    for _, v := range s {
      fmt.Println(v)
    }
  }

  func main() {
    a := []int{1, 2, 3, 4, 5}
    b := []float64{1.1, 2.2, 3.3, 4.4, 5.5}

    Print(a)
    Print(int)(a)
    Print(b)
  }
$ go tool go2go run hoge.go2

warning: GOPATH set to GOROOT (/Users/fskmt/goroot) has no effect
1
2
3
4
5
1
2
3
4
5
1.1
2.2
3.3
4.4
5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment