run go as shell
Try some basic idea without creating a file, compiling, running.
Just like what python does.
- golang 1.6 (if you are using golang 1.6-,
go get github.com/chzyer/readline
is required) - goimports(strongly recommend which help you import package you are using)
go get github.com/kuangchanglang/goshell
$ goshell
>>> sum := 0
>>> for i:=0; i<=100; i++{
>>> sum += i
>>> }
>>> import "fmt"
>>> fmt.Println(sum)
5050
>>>
$ goshell
>>> func fi(n int) int{
>>> if n < 0 {
>>> return 0
>>> }
>>> if n <= 2{
>>> return 1
>>> }
>>> return fi(n-1) + fi(n-2)
>>> }
>>> fmt.Println(10)
10
>>> fmt.Println(3)
3
>>> for i:=0;i<10;i++{
>>> fmt.Println(fi(i))
>>> }
1
1
1
2
3
5
8
13
21
34
- type "quit" to exit
- run
stty erase ^h
to enable backspace, runstty erase ^?
to recover