This project provides an interactive environment for evaluating go expressions.
Yeah, we know of some others. I think this one has more promise. The heavy lifting for eval is provided by the Carl Chatfield's eval package.
- Make sure our Go environment is setup, e.g. $GOBIN, $GOPATH, ...
- Make sure you have a version 1.2ish Go installed.
$ go get github.com/rocky/go-fish
$ cd $GOPATH/src/github.com/rocky/go-fish
$ make install # or look at Makefile
If you have go-gnureadline installed and want the GNU readline support. In addition to the above try:
$ make go-fish-grl
$ make install
If you have remake installed, you can change make above to remake -x to see the simple go and shell commands that get run. (And remake --tasks is also your friend.)
Run go-fish
or go-fish-grl
. For now, we have only a static
environment provided and that's exactly the environment that go-fish
uses for itself. (In other words this is ideally suited to introspect
about itself). Since it uses eval and that package is a reasonable size program,
many of the packages like os, fmt, strconv, errors, exec, etc. are
available. Look at the import list in file repl_imports.go for the
exact list, or type pkgs inside go-fish (as shown below) for a list.
Two global variables have been defined: env, and results. env
the environment that is defined, again largely by
eval_imports.go. As you enter expresions, the results are saved in
slice results. To quit, enter Ctrl-D
(EOF) or the word quit
.
Here's a sample session:
$ ./go-fish
== A simple Go eval REPL ==
Results of expression are stored in variable slice "results".
The environment is stored in global variable "env".
Enter expressions to be evaluated at the "gofish>" prompt.
To see all results, type: "results".
To quit, enter: "quit" or Ctrl-D (EOF).
To get help, enter: "help".
gofish> 10+len("abc" + "def")
Kind = Type = int
results[0] = 16
gofish> os.Stderr
os.Stderr
Kind = ptr
Type = *os.File
results[1] = &{0x1882d120}
gofish> fmt.Fprintln(os.Stderr, os.Getenv("GOPATH"))
/home/rocky/go
Kind = Multi-Value
15, nil
gofish> help *
All command names:
help packages quit
gofish> packages
All imported packages:
ansi binary eval fmt math rand scanner sync time
ast bufio exec io os reflect sort syscall token
atomic bytes filepath ioutil parser repl strconv tabwriter unicode
big errors flag log pprof runtime strings testing utf8
gofish> pkg ansi
=== Package ansi ("github.com/mgutz/ansi"): ===
Constants of ansi:
Reset
Functions of ansi:
Color ColorCode ColorFunc DisableColors
gofish> quit
go-fish: That's all folks...
$
- What's left to do?
- go-play: A locally-run HTML5 web interface for experimenting with Go code
- gub: A Go debugger based on the SSA interpreter