Go 提供 REPL 吗? [英] Does Go provide REPL?

查看:28
本文介绍了Go 提供 REPL 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

交互式环境对程序员非常有帮助.但是,Go 似乎没有提供它.我的理解正确吗?

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

推荐答案

不,Go 不提供 REPL.

No, Go does not provide a REPL.

但是,如前所述,Go Playground(这是新网址)非常方便.Go 作者也在考虑为它添加一个功能丰富的编辑器.

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.

如果您想要本地的东西,请考虑安装 hsandbox.使用 hsandbox go 简单地运行它会拆分您的终端屏幕(使用 screen),您可以在其中在顶部编写代码,并在每次保存时在底部查看其执行输出.

If you want something local, consider installing hsandbox. Running it simply with hsandbox go will split your terminal screen (with screen) where you can write code at the top and see its execution output at the bottom on every save.

Go 标准命令中有一个 gotry,用于计算表达式(带有可选的包名),可以像 gotry 1+2gotry fmt 'Println("hello")' 来自 shell.它不再可用,因为没有多少人实际使用它.

There was a gotry among standard Go commands, which used to evaluate expressions (with an optional package name), and could be run like gotry 1+2 and gotry fmt 'Println("hello")' from shell. It is no longer available because not many people actually used it.

我也看到过为 Go 构建 REPL 的第三方项目,但现在我只能找到其中两个的链接:igogo-repl.我不知道它们的效果如何.

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.

我的两分钱:编译速度使得为 Go 编写 REPL 成为可能,因为它也有助于构建这里提到的工具,但同样的速度使得 REPL 的必要性降低.每次我想在 Go 中测试无法在 Playground 中运行的东西时,我都会打开一个简单的 .go 文件并开始编码并简单地运行代码.当 Go 1 中的 go 命令使单命令构建过程成为可能并且更容易时,这将更加容易.

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 the go command in Go 1 makes one-command build process possible and way easier.

更新: Go 的最新每周版本添加了 go 命令,可用于非常轻松地构建文件:编写您的 prog.go文件并运行 go build prog.go &&./prog

UPDATE: Latest weekly release of Go added go command which can be used to very easily build a file: write your prog.go file and run go build prog.go && ./prog

更新 2:使用 Go 1,您可以使用 go run filename.go

UPDATE 2: With Go 1 you can directly run go programs with go run filename.go

更新 3:gore 是一个看起来很有趣的新项目.

UPDATE 3: gore is a new project which seems interesting.

这篇关于Go 提供 REPL 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆