Giter Site home page Giter Site logo

repl's Introduction

Build Status Coverage State

repl

Getting Started

Requirements

  • go 1.13
  • goimports
  • gofmt
go get golang.org/x/tools/cmd/goimports

Installing repl

go get github.com/golobby/repl
go install github.com/golobby/repl

Why

repl is a REPL, Read-Eval-Print-Loop. In scripting languages like PHP or Python there is an environment called repl, which is basically a command line interface that is connected to the language interpreter and it would show instantly the result of user input. In Golang we don't have this feature by default but it does'nt mean that we cannot benefit the power that repl gives us.

How

repl parses the input and put the code you entered in one of these categories:

  • Imports
  • Var declaration/assignment
  • type definition
  • function definition
  • function calls

then repl creates a file from state of the session running.

repl Pipeline

repl Prompt -> goimports -> go compiler -> shows result of compile

Features

Global Access to vars

In a repl you need to have access to the vars defined no matter what scope you are in, repl provides this feature by defining all vars in a global scope.

repl> func someFunc() string {
...repl>     return fmt.Sprint(a)
...repl> }
repl> a = 2
repl> someFunc() // 2

Variable Redefine/assignment

repl does not care about either type or value of a variable, so you can redefine or change type of variable with ease.

repl> x := 3
repl> x := "amirreza"
repl> x := someType{}
repl> var x = 5
// all above codes are valid in a repl interpreter

Instant Expression Evaluation

repl can easily evaluate any valid Go expression.

repl> 2 // <int> 2
repl> 2*3*(2+1) // <int> 18
repl> "Hello World" // <string> "Hello World"

Automated Imports

repl uses the power of goimports so it can almost identify all packages you use and automatically import them for you.

repl> fmt.Println("Hello") // no need for manual import, goimports will take care of that

Helpful Error Messages

repl does not suppress any error message so you can see exact error message from go toolchain

Go module discovery

repl build from ground up to be compatible with go modules, so when you fire up a repl in go project which is a go module project repl instantly identifies your module and imports it as a module with local path, so you can access all your public types and functions.(watch Demo)

Shell Commands

Go Doc

go doc is available as a shell command so you can access any document about any package with repl.

repl> :doc fmt
repl> :doc json.Marshal

Eval

repl> :e 1+2
// <int> 3
repl> :e "HelloWorld"
// <string> "HelloWorld"

Dump

shows formatted view of current session state.

repl> :dump

Pop

pops latest entered code from session.

repl> :pop

file

file shows exactly code that will be generated from current state of session.

repl> :file

Demo

asciicast

TODO

Code completion (with gocode)

repl's People

Contributors

amirrezaask avatar miladrahimi 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

Watchers

 avatar  avatar  avatar

Forkers

hu13

repl's Issues

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.