Skip to content
A Simple Lisp that compiles to Go
Branch: master
Clone or download
Pull request Compare This branch is 84 commits ahead of rcarmo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
cmd/zylisp
common
core
doc @ 6814b73
examples
generator
lexer
parser
repl
tests
.env
.gitignore
.gitmodules
.travis.yml
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
main.go

README.md

ZYLISP

Build Status Tag Go version

A Simple Lisp that compiles to Go

Status

This project was largely abandoned in 2014, but revived in 2017 with updates from various forks as well as some additional cleanup work. It was brought into the ZYLISP Github org for exploratory purposes, and received more loving tweaks and cleanups. More to come ...

Includes

  • Lexer based on Rob Pike's Lexical Scanning in Go
  • Simple recursive parser, supporting ints, floats, strings, bools
  • TCO via loop/recur
  • AST generating REPL included

Supported Lisp Functions

  • +
  • -
  • *
  • mod
  • let
  • if
  • ns
  • def
  • fn
  • All pre-existing Go functions

Example Code

This is from the examples (all of which successfully compile from Lisp to both Go source as well as bytecode):

(ns main
  "fmt"
  "github.com/zylisp/zylisp/core")

(def factorial (fn [n]
  (if (< n 2)
    1
    (* n (factorial (+ n -1))))))

(def main (fn []
  (fmt/printf "10! = %d\n"
              (int
                (assert
                  float64 (factorial 10))))))

See examples for some more examples (they are Project Euler solutions).

Installation

$ go get github.com/zylisp/zylisp/cmd/zylisp

Development

$ git clone git@github.com:zylisp/zylisp.git
$ cd zylisp
$ . .env # optional, depending upon your local Go setup
$ make

That last step creates the zylisp binary and runs all the tests.

Note that the ZYLISP instructions and docs assume that the git clone has make made in the directory src/github.com/zylisp, where the parent directory of src is on the GOPATH.

Usage

For usage as a REPL as well as a CLI, see the command documentation here:

In short, once compiled, you may pass a flag for one of the supported REPL modes (e.g., -ast), or use zylisp as a CLI tool (i.e., compiler), with the -cli flag.

General package reference documentation is available here:

Docker Support

For those who have docker installed and do not wish to install Go, you may try out the various REPLs via docker commands, e.g.:

docker run -it zylisp/zylisp:latest -ast
Okay, 3, 2, 1 - Let's jam!

Welcome to

/^^^^^^^^/^^ /^^      /^^ /^^       /^^ /^^^^^^^^ /^^^^^^^^^
       /^^    /^^    /^^  /^^       /^^ /^^       /^^    /^^
      /^^      /^^ /^^    /^^       /^^ /^^       /^^    /^^
    /^^          /^^      /^^       /^^ /^^^^^^^^ /^^^^^^^^^
   /^^           /^^      /^^       /^^       /^^ /^^
 /^^             /^^      /^^       /^^ /^^   /^^ /^^
/^^^^^^^^^^^     /^^      /^^^^^^^^ /^^ /^^^^^^^^ /^^

ZYLISP version: 0.8.0
Build: master@1e52cac, 2019-04-07T04:16:06Z
REPL Mode: AST
Go version: go1.12.2

        Docs: https://zylisp.github.io/zylisp/
     Project: https://github.com/zylisp/zylisp
Instructions: Simply type any form to view the generated Go AST.
        Exit: ^D or ^C

AST>

Futhermore, since zylisp is the entrypoint for the Docker image, the run command may receive all the options that the zylisp binary receives, including the help flag:

$ docker run -it zylisp/zylisp:latest -h
Usage of zylisp:
  -ast
    	Enable AST mode
  -bytecode
    	Enable byte-code compilation from generated Go
  -cli
    	Run as a CLI tool
  -dir string
    	Default directory for writing operations
  -go
    	Enable Go code-generation mode
  -lisp
    	Enable LISP mode
  -loglevel string
    	Set the logging level (default "warning")
  -o string
    	Default filename for writing operations
  -version
    	Display version/build info and exit

Note that the ZYLISP docker images are very small, usually weighing in about 4 MB in size.

History

In December of 2013, @jcla1 pushed his initial work on Gisp to Github. He hacked on it over the course of the next six months. In December of 2014, it was then picked up by @masukomi who hacked on it for about a month. Later, in 2017, @rcarmo forked the original and merged in @masukomi's changes, merged a (still-open) pull request from @m90, and made a few updates himself.

In early 2019 @oubiwann had created a zylisp Github org where various Go Lisp's were being explored. In particular, the zygomys project (which was based on a different Lisp/Go lineage, Glisp, which was started in 2014). The ZYLISP Github org took inspiration in its name from the zygomys project. However, work with zygomys was abandoned after it became clear that Go interop was very awkward in this Lisp dialect. It was at this point that @rcarmo's fork was forked into the ZYLISP org where it was eventually renamed from Gisp to ZYLISP.

Versions

None of the previous forks tagged any of the work with versions, as such, this fork has retroactrively tagged the various phases of the project's work with the following:

Version Date Repo Notes
0.8.0 2019-04-06 zylisp Code rename to zylisp, cleanup, Go modules, docker
0.7.0 2019-03-12 zylisp CLI support, improved compiling options, logging
0.6.0 2019-02-28 zylisp Compatibility release, docs updates
0.5.0 2017-08-25 rcarmo Merged PR from m90, minor fixes and tweaks
0.4.0 2014-12-20 masukomi Refactoring, tests, error handling
0.3.0 2014-06-29 jcla1 Updates and a merged PR from kedebug
0.2.0 2014-02-12 jcla1 Follow-up work, control structures, etc.
0.1.0 2014-01-25 jcla1 Core original work

Credits

  • @jcla1 for the initial implementation
  • @masukomi for adding a number of tests and checks
  • @m90 for README fixes
  • The ZYLISP project for new development

License

MIT

You can’t perform that action at this time.