vito/go-repl — pull request #6 by eternia478 (2014-04-03 06:05:12+00:00)
Title: Pull request for changes compatible with Go 1.0

This is actually a fork from jessta/go-repl 2 years ago, in which he made changes to remove the dependency on the "container/vector" package and other things.

The rest of the commits are changes made to make it compatible with Go 1.0 and with additional features:
- Fix reliance on deprecated ParseStmtList and ParseDeclList. The redefinition hacks are partially taken from the go-eval project.
- Fix compiling error in the case that $GOBIN is not set (although it assume 64-bit amd64 architecture for now if that's the case).
- Added rollback for bad assignments or declarations.
- Added multiple argument functionality to import and removal
- Added line numbers to source inspection and allow removal of specific lines of code/declaration/package importing.
- Added many aliases to the set of special commands (see the help menu).
- Added "auto" for autosetup to include some basic packages and shortcuts for easy testing.
- Fix some bugs like resetting or declaration/code parsing order or committing only one command at a time.

About the removal, it's based on the newly added line numbers on the side. So if the source is this:
```
fmt> !

package main
p0: import "fmt"

d0: var b = 9

func noop(_ interface{}) {}

func main() {
c0:	a := 1;
noop(a);
c1:	fmt.Println(a);
c2:	b := 8;
noop(b);
c3:	fmt.Println(b);
}
```
Then "-c2" would remove the second to last line of code, and "-c0,1" would remove the first two lines of code. "-d" and "-d0" would both remove the global declaration of b, and "-p" and "-p0" would both remove the package "fmt" (although that would cause instability). This is the most complicated part of the set of changes made, done because at the time I really wanted to remove some line of code while testing.

Also, I made it note instability only for compilation reasons, so things like arr[1000] for a 5-int slice arr would give an error, but not be marked unstable. Of course, this can be tested with "run" to see.

I'm considering if I should add "insert code" functionality and fix the fact that you cannot execute (in the default case) multiple commands at once (only the last one is run). There is also the matter of testing, but I'll leave that for later. A further task is to also import personal files to just up and run them in the go-repl environment.

I believe it is worth putting some work into this interpreter/REPL, since igo and go-eval is still quite incomplete. When I tried them out, I found that it was annoying that they required using Go 1.2 and onward (which is annoying when the apt repository only has 1.0) and they cannot import. The need for importing is actually quite huge, as much of my testing is with functions defined in packages. I remember doing that many times for the Python interpreter, and I was quite annoyed with that igo didn't have that functionality implemented (which, frankly, makes it impossible to test out things because many implementations uses some package or another). Although go-repl is a bit hacky in the approach that it requires re-compiling everything for every command, it is ,much more useful for basic testing.

This version can be run from the following set of commands for now (in Ubuntu or Debian):
$ sudo apt-get install golang-go
$ sudo apt-get install golang
$ go version
go version go1
$ sudo go get github.com/eternia478/go-repl
$ export PATH=$PATH:/usr/lib/go/bin/
$ go-repl

It is suggest for users to include rlwrap, to make typing easier (up and down for history, left and right to edit the input in the middle). A simple apt-get install rlwrap would do.