Giter VIP home page Giter VIP logo

go-repl's Introduction

A compiling Go REPL.

Builds up Go source as the session goes on, compiles and runs it with every input.

A "!" in front of the input means it's in "unstable" mode, e.g. a package has been imported and isn't used, or errors occur in the source.

Example session:

Welcome to the Go REPL!
Enter '?' for a list of commands.
> ?
Commands:
    ?	help
    + (pkg)	import package
    - (pkg)	remove package
    -[dpc]	pop last (declaration|package|code)
    ~	reset
    : (...)	add persistent code
    !	inspect source
> a := 6
> b := 7
> println(a * b)
42
> + fmt
! fmt> fmt.Println("Hello, world!")
Hello, world!
! fmt> println("This won't work since fmt doesn't get used.")
Compile error: /tmp/gorepl.go:2: imported and not used: fmt

! fmt> : fmt.Print()
fmt> println("Now it will!")
Now it will!
fmt> func b(a interface{}) { fmt.Printf("You passed: %#v\n", a); }
fmt> b(1)
Compile error: /tmp/gorepl.go:14: cannot call non-function b (type int)

fmt> !
package main
import "fmt"

func b(a interface{})	{ fmt.Printf("You passed: %#v\n", a) }

func noop(_ interface{}) {}

func main() {
    a := 6;
    noop(a);
    b := 7;
    noop(b);
    fmt.Print();
}

fmt> -d
fmt> !
package main
import "fmt"

func noop(_ interface{}) {}

func main() {
    a := 6;
    noop(a);
    b := 7;
    noop(b);
    fmt.Print();
}

fmt> func dump(a interface{}) { fmt.Printf("You passed: %#v\n", a); }
fmt> dump("Phew, there we go.")
You passed: "Phew, there we go."
fmt> -d
fmt> -c
! fmt> - fmt
> + math
! math> println(math.Pi)
+3.141593e+000
! math> + fmt
! math fmt> fmt.Println(math.Pi)
3.1415927
! math fmt> 

TODO: Write automatic test with the above example session as input and expected output.

go-repl's People

Contributors

eternia478 avatar jessta avatar tianyicui avatar vito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

go-repl's Issues

Doesn't appear to work with latest hg checkout

ricky@lightning:~/dev/go$ ./repl
Welcome to the Go REPL!
Enter '?' for a list of commands.

a := 6
Parse error: go-repl:1:1: expected declaration, found 'IDENT' a (and 2 more errors)

Unable to import packages within gopath

Basically this stems from being to test custom go code using this repl. If i import something in my gopath, it always fails

Compile error: /tmp/gorepl.go:2: can't find import:

panic: fork/exec /tmp/gorepl: no such file or directory

 Welcome to the Go REPL!
Enter '?' for a list of commands.
> a := 2
CODE:  a := 2;
panic: fork/exec /tmp/gorepl: no such file or directory

goroutine 1 [running]:
main.run(0xc000073ea0, 0xc0000ca150)
        /home/janek/dev/golang/go-repl/main.go:174 +0x26e
main.main()
        /home/janek/dev/golang/go-repl/main.go:578 +0xc2a

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.