Does Go provide REPL?

前端 未结 12 523
[愿得一人]
[愿得一人] 2020-11-30 17:22

The interactive environment is VERY helpful for a programmer. However, it seems Go does not provide it. Is my understanding correct?

相关标签:
12条回答
  • 2020-11-30 18:07

    If you're a Vim user, the vim-go plugin (https://github.com/fatih/vim-go) provides a command (GoRun) to run and print the output of the current buffer. You still have to include all the boilerplate code of a main Go file, but it still provides a convenient way to quickly test code snippets in your local environment.

    enter image description here

    HTH

    0 讨论(0)
  • 2020-11-30 18:09

    Go code can be run in a REPL-like way in Visual Studio Code with the Go extension and Code Runner extension. Click the Run triangle ▶ which is marked by the mouse cursor in the below screenshot to run the code and show the results in the Output pane at the bottom of Visual Studio Code.

    When programming with Go Visual Studio Code will suggest additional Go extensions that can be installed to extend Visual Studio Code's functionality.

    0 讨论(0)
  • 2020-11-30 18:11

    You also have a recent (March 2013) project called gore from Sriram Srinivasan, which can be useful:

    gore is a command-line evaluator for golang code -- a REPL without a loop, if you will.
    It is a replacement for the go playground, while making it much easier to interactively try out bits of code: gore automatically supplies boiler-plate code such as import and package declarations and a main function wrapper.
    Also, since it runs on your own computer, no code is rejected on security grounds (unlike go playground's safe sandbox mode).

    0 讨论(0)
  • 2020-11-30 18:11

    Have you tried the Go Playground?

    About the Go Playground

    The Go Playground is a web service that runs on golang.org's servers. The service receives a Go program, compiles, links, and runs the program inside a sandbox, then returns the output.

    0 讨论(0)
  • 2020-11-30 18:12

    Try motemen/gore

    Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

    https://github.com/motemen/gore

    enter image description here

    0 讨论(0)
  • 2020-11-30 18:12

    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

    0 讨论(0)
提交回复
热议问题