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

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

问题描述

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

解决方案

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



如果您想要本地的东西,可以考虑安装 hsandbox 。简单地使用 hsandbox go 运行它将会拆分你的终端屏幕(使用 screen ),你可以在上面写代码,在每次保存时都会在底部看到它的执行输出。



标准Go命令中有一个 gotry ,它使用以评估表达式(使用可选的包名称),并且可以像 gotry 1 + 2 gotry fmt'Println(hello)' 来自shell。它已不再可用,因为实际使用它的人并不多。



我也看到了为Go创建REPL的第三方项目,但现在我只能找到指向其中两个: igo go-repl



但是要真正回答您的主要问题:不,Go不提供REPL。



我的两美分:编译速度使得为Go编写REPL成为可能,因为它也帮助构建了这里提到的工具,但同样的速度使得REPL变得不那么必要。每当我想在Go中测试一些我无法在Playground中运行的东西时,我会打开一个简单的 .go 文件,并开始编码并简单地运行代码。如果Go 1中的 go 命令使得单命令构建过程变得更简单和容易,这将更加容易。



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



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



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

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

解决方案

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 (with screen) 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 like gotry 1+2 and gotry 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.

But to actually answer your main question: no, Go does not provide REPL.

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.

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

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.

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

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