Is there a Golang terminal shell? Is it possible for a compiled language?

Viewed 2661

Recently I'm interested in Golang.

When I was learning Python I kicked off a terminal shell and just practised throwing it different data, files, making many trivial silly operations, it's such a nice way to interact with a new language and it's super helpful for writing new programs.

I wonder- I guess because Golang is a compiled language like Java it's not possible to have such a terminal shell. Is that right? If so- what's the real technical reason why it can't work?

3 Answers

Take a look at gomacro

go get -u github.com/cosmos72/gomacro

~ $ gomacro
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2018-2019 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> import "fmt"
gomacro> a := 10
gomacro> fmt.Println(a)
10
3   // int
<nil>   // error
gomacro>

Not a direct solution, but one thing to try is a Jupyter notebook with a Go kernel like https://github.com/gopherdata/gophernotes

While you'll be using the Jupyter browser interface instead of the terminal, you can still do terminal-like things like execute shell commands and tab-complete. I've found this useful when wanting to import a library I'm not familiar with and quickly trying its functions, for example.

Related