lisp

package module
v0.0.0-...-edd80f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2019 License: MIT Imports: 7 Imported by: 1

README

A silly toy LISP interpreter based on the SICP analyzing interpreter.

This was written to demonstrate how to use closures to build embedded DSLs in go.

Run

$ go get jsouthworth.net/go/lisp
$ go run jsouthworth.net/go/lisp/cmd/repl
]=> (load "test.scm")
]=> (map square (list 1 2 3 4))
]=> (map fib (10 20 30 40))

License

MIT see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OK = Sym("OK")

Functions

func Quote

func Quote(e Expr) quote

Types

type Applier

type Applier interface {
	Apply(args ...Expr) Expr
}

type Bool

type Bool bool

func IsTrue

func IsTrue(exp Expr) Bool

func (Bool) Eval

func (b Bool) Eval(e Env) Expr

type Env

type Env struct {
	// contains filtered or unexported fields
}

func EnvNew

func EnvNew() Env

func InitEnv

func InitEnv() Env

func (*Env) Define

func (e *Env) Define(name Sym, val Expr)

func (*Env) Eval

func (e *Env) Eval(exp Expr) Expr

func (*Env) Extend

func (e *Env) Extend(vars []Sym, vals []Expr) Env

func (*Env) Lookup

func (e *Env) Lookup(name Sym) Expr

func (*Env) SetValue

func (e *Env) SetValue(name Sym, val Expr)

type Expr

type Expr interface {
	Eval(e Env) Expr
}
var False Expr = Bool(false)
var Nil Expr = null{}
var True Expr = Bool(true)

func Analyze

func Analyze(exp Expr) Expr

func Apply

func Apply(procedure Expr, arguments ...Expr) Expr

func Car

func Car(e Expr) Expr

func Cdr

func Cdr(e Expr) Expr

func Cons

func Cons(a, b Expr) Expr

func Define

func Define(name Expr, exp Expr) Expr

func Eval

func Eval(exp Expr) Expr

func If

func If(predicate, consequent, alternate Expr) Expr

func Lambda

func Lambda(parameters Expr, body ...Expr) Expr

func List

func List(vals ...Expr) Expr

func Load

func Load(file Expr) Expr

func Num

func Num(rat *big.Rat) Expr

func Read

func Read(program string) Expr

func Sequence

func Sequence(exprs ...Expr) Expr

func Set

func Set(name Expr, exp Expr) Expr

func Unquote

func Unquote(e Expr) Expr

func Var

func Var(name Expr) Expr

type Number

type Number struct {
	// contains filtered or unexported fields
}

func Zero

func Zero() Number

func (Number) Eval

func (n Number) Eval(e Env) Expr

func (Number) String

func (n Number) String() string

type Primitive

type Primitive func(...Expr) Expr

func (Primitive) Apply

func (p Primitive) Apply(args ...Expr) Expr

func (Primitive) Eval

func (p Primitive) Eval(e Env) Expr

type Proc

type Proc func(Env) Expr

func (Proc) Eval

func (p Proc) Eval(e Env) Expr

type String

type String string

func (String) Eval

func (s String) Eval(e Env) Expr

func (String) String

func (s String) String() string

type Sym

type Sym string

func (Sym) Eval

func (s Sym) Eval(e Env) Expr

func (Sym) String

func (s Sym) String() string

Directories

Path Synopsis
cmd
repl command
square command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL