The interactive environment is VERY helpful for a programmer. However, it seems Go does not provide it. Is my understanding correct?
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
- IntelliJ 2017.1.2 GOLANG debug does not work on br
No, Go does not provide a REPL.
However, as already mentioned, Go Playground (this is the new URL) is very handy. The Go Authors are also thinking about adding a feature-rich editor to it.
If you want something local, consider installing hsandbox. Running it simply with
hsandbox go
will split your terminal screen (withscreen
) where you can write code at the top and see its execution output at the bottom on every save.There was a
gotry
among standard Go commands, which used to evaluate expressions (with an optional package name), and could be run likegotry 1+2
andgotry fmt 'Println("hello")'
from shell. It is no longer available because not many people actually used it.I have also seen third party projects for building a REPL for Go, but now I can only find links to two of them: igo and go-repl. How well do they work I don't know.
My two cents: Speed of compilation makes writing a REPL possible for Go, as it has also helped building the tools mentioned here, but the same speed makes REPL less necessary. Every time I want to test something in Go that I can't run in Playground I open a simple
.go
file and start coding and simply run the code. This will be even easier when thego
command in Go 1 makes one-command build process possible and way easier.UPDATE: Latest weekly release of Go added
go
command which can be used to very easily build a file: write yourprog.go
file and rungo build prog.go && ./prog
UPDATE 2: With Go 1 you can directly run go programs with
go run filename.go
UPDATE 3:
gore
is a new project which seems interesting.You also have a recent (March 2013) project called gore from Sriram Srinivasan, which can be useful:
You may also like to try https://github.com/haya14busa/goplay This enables you to run go code files from your terminal directly to the Go Playground
Try motemen/gore
https://github.com/motemen/gore