• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Lisp implementation in Go

go-lisp.go

A simple Lisp interpreter developed in Go.

Go is a perfect fit for building a Lisp interpreter, since it's portable, garbage collected and fast. The result is a one file distribution, which makes it easy to deploy. The garbage collection unloads that work from the interpreter, using the Go already tuned GC.

Inspired by: [http://norvig.com/lispy.html]

Setup

Install Go

http://golang.org/doc/install

Make sure your GOPATH is setup correctly, something like

$ export GOPATH=$HOME/go
$ mkdir -p $GOPATH

Clone the repo

$ go get github.com/janne/go-lisp

Run the tests

$ go test github.com/janne/go-lisp/lisp

Run the example

$ go-lisp -file $HOME/go/src/github.com/janne/go-lisp/example.lsp

Run it interactively

$ go-lisp -i

Syntax

(quote exp)

Return the exp literally; do not evaluate it.

(quote (a b c))

Returns:

(a b c)

(if test conseq alt)

Evaluate test; if true, evaluate and return conseq; otherwise evaluate and return alt.

(if (< 10 20) (+ 1 1) (+ 3 3))

Returns:

2

(set! var exp)

Evaluate exp and assign that value to var, which must have been previously defined (with a define or as a parameter to an enclosing procedure).

(set! x2 (* x x))

(define var exp)

Define a new variable and give it the value of evaluating the expression exp.

(define r 3)
(define square (lambda (x) (* x x)))

(lambda (var...) exp)

Create a procedure with parameter(s) named var... and the expression as the body.

(lambda (r) (* 3.141592653 (* r r)))

(begin exp...)

Evaluate each of the expressions in left-to-right order, and return the final value.

(begin (define x 1) (set! x (+ x 1)) (* x 2))

Returns:

4

(proc exp...)

If proc is anything other than one of the symbols if, set!, define, lambda, begin, or quote then it is treated as a procedure. It is evaluated using the same rules defined here. All the expressions are evaluated as well, and then the procedure is called with the list of expressions as arguments.

(square 12)

Returns:

144

License

Licensed under MIT license.

More Repositories

1

model_translations

Minimal implementation of Globalize2 style model translations
Ruby
31
star
2

bcm2835

Go package for the bcm2835 as used in the Raspberry Pi
C
29
star
3

unofficial_simplenote

Google Chrome extension for accessing Simplenote
JavaScript
24
star
4

pluscodes

Javascript library to encode and decode plus codes
TypeScript
17
star
5

vortaro

A simple, yet powerful, offline Esperanto-English dictionary iPhone app
Swift
6
star
6

dotfiles

Dotfiles with Docker support
Vim Script
6
star
7

elm-hexagons

Initial work on hex tiled game art
Elm
3
star
8

incrementor

Google Chrome Extension to increment last number in URL
JavaScript
3
star
9

elm-shunting-yard

Parser of simple mathemetical expressions
Elm
3
star
10

meteor-ludo

CoffeeScript
3
star
11

md2html

Command line tool for coverting John Gruber's Markdown formatted text to HTML
2
star
12

rocky

Google Chrome extension for reading the swedish Rocky comic strip
JavaScript
2
star
13

snacka

Multi user voice chat
JavaScript
2
star
14

janitor

A modern, modal editor
Go
2
star
15

rackless

JavaScript
2
star
16

flutter-test

C++
2
star
17

newsroom-app

Mynewsdesk Newsroom as a Mac App (because I can), Elm + Electron
Elm
2
star
18

arduino_pomodoro

Java
2
star
19

gothenburg

Vad skulle du heta, om du bodde i Gรถteborg?
JavaScript
2
star
20

markdown.vim

Markdown VIM syntax files
Vim Script
2
star
21

vagrant

My vagrant setup
Ruby
1
star
22

freecell-svelte

Freecell PWA in Svelte
CSS
1
star
23

sjostadsbussen

JavaScript
1
star
24

round_robin

Library and tasks to handle round robin style workers
Ruby
1
star
25

APIdock

Unofficial Google Chrome extension to search Ruby, Rails and RSpec docs on apidock.com
1
star
26

dotvim

My vim dotfiles
Vim Script
1
star
27

events

Basic Java/Struts/Hibernate setup
Java
1
star
28

tofu

Very simple todo list CLI app
Ruby
1
star
29

tofu_mobile

Tofu Mobile
JavaScript
1
star
30

elm-matte

Simple math exercises for children (with copy in Swedish)
Elm
1
star
31

kalahelm

Elm implementation of Kalaha
Elm
1
star
32

DartGPT

ChatGPT CLI client in Dart
Dart
1
star
33

tofu_web

Tofu for the web
Ruby
1
star