lisp

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RawCore string
View Source
var Version string = "v0.0.57"

Functions

func EnvKeys

func EnvKeys(m *Env) []string

EnvKeys returns the keys of an environment, including any parents' keys.

func EvalExprs

func EvalExprs(exprs []Sexpr, e *Env, doPrint bool) error

Evaluate a list of expressions. Return any errors.

func IsBalanced

func IsBalanced(tokens []Token) (bool, error)

IsBalanced returns true iff parens are balanced

func LexParseEval

func LexParseEval(s string, e *Env) error

LexParseEval lexes, parses, and evaluates the given string.

func LexRepr

func LexRepr(i Token) string

LexRepr returns a string representation of a known lexeme.

func LoadFile

func LoadFile(e *Env, filename string) error

func LongDocStr

func LongDocStr(e *Env) (string, error)

LongDocStr returns a long, Markdown docstr for a function, macro or special form.

func ReadLine

func ReadLine() (string, error)

ReadLine reads a line from stdin "robustly".

func ShortDocStr

func ShortDocStr(e *Env) (string, error)

ShortDocStr returns an abbreviated explanation of all functions, macros and special forms.

Types

type Atom

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

Atom is the primitive symbolic type.

var True Atom = Atom{"t"}

True is the generic truthy item. Everything but Nil is true. See also Nil in cons.go.

func (Atom) Equal

func (a Atom) Equal(b Sexpr) bool

Equal returns true if the receiver and the arg are both atoms and have the same name

func (Atom) String

func (a Atom) String() string

type Builtin

type Builtin struct {
	Name string
	Fn   func([]Sexpr, *Env) (Sexpr, error)
	// Fn must take at least this many arguments:
	FixedArity int
	// If true, fn can take more arguments:
	NAry     bool
	Doc      *ConsCell
	Args     *ConsCell
	Examples *ConsCell
}

Builtin represents a function with a native (Go) implementation.

func (Builtin) Equal

func (b Builtin) Equal(o Sexpr) bool

Equal returns true if the receiver and the arg are both builtins and have the same name.

func (Builtin) Eval

func (b Builtin) Eval(e *Env) (Sexpr, error)

Eval for builtin returns itself.

func (Builtin) String

func (b Builtin) String() string

type ConsCell

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

ConsCell is a cons cell. Use Cons to create one.

var Nil *ConsCell = nil

Nil is the empty list / cons cell. Cons with Nil to create a list of one item.

func Cons

func Cons(i Sexpr, cdr Sexpr) *ConsCell

Cons creates a cons cell.

func (*ConsCell) Equal

func (c *ConsCell) Equal(o Sexpr) bool

Equal returns true iff the two S-expressions are equal cons-wise

func (*ConsCell) Error

func (c *ConsCell) Error() string

A cons (list) can be used as an error, and consed to, to make a stacktrace:

func (*ConsCell) String

func (c *ConsCell) String() string

type Env

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

Env stores a local environment, possibly pointing to a caller's environment.

func InitGlobals

func InitGlobals() Env

func (*Env) Lookup

func (e *Env) Lookup(s string) (Sexpr, bool)

Lookup returns the value of a symbol in an environment or its parent(s).

func (*Env) Set

func (e *Env) Set(s string, v Sexpr) error

Set sets the value of a symbol in an environment.

func (*Env) SetTopLevel

func (e *Env) SetTopLevel(s string, v Sexpr) error

SetTopLevel sets the value of a symbol in the top-level environment.

func (*Env) String

func (e *Env) String() string

func (*Env) Update

func (e *Env) Update(s string, v Sexpr) error

Update updates the value of a symbol in an environment, or in a parent.

type Number

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

Number wraps a big.Int (for now)

func Num

func Num(ob interface{}) Number

Num is a `num` constructor, which can take a string or a ("normal") number.

func (Number) Add

func (n Number) Add(o Number) Number

Add returns the sum of the two numbers.

func (Number) Div

func (n Number) Div(o Number) Number

Div returns the (integer) quotient of the two numbers.

func (Number) Equal

func (n Number) Equal(o Sexpr) bool

Equal returns true if the two numbers are equal.

func (Number) Greater

func (n Number) Greater(o Number) bool

Greater returns true if the first number is greater than the second.

func (Number) GreaterEqual

func (n Number) GreaterEqual(o Number) bool

GreaterEqual returns true if the first number is >= the second.

func (Number) Less

func (n Number) Less(o Number) bool

Less returns true if the first number is less than the second.

func (Number) LessEqual

func (n Number) LessEqual(o Number) bool

LessEqual returns true if the first number is <= the second.

func (Number) Mul

func (n Number) Mul(o Number) Number

Mul returns the product of the two numbers.

func (Number) Neg

func (n Number) Neg() Number

Neg returns the negative of the number.

func (Number) Rem

func (n Number) Rem(o Number) Number

Rem returns the remainder of the division of two numbers.

func (Number) String

func (n Number) String() string

String returns the string representation of the number.

func (Number) Sub

func (n Number) Sub(o Number) Number

Sub returns the difference of the two numbers.

type Sexpr

type Sexpr interface {
	String() string
	Equal(Sexpr) bool
}

Sexpr is a general-purpose interface for representing S-expressions.

func Parse

func Parse(tokens []Token) ([]Sexpr, error)

Parse takes a slice of tokens and returns a slice of Sexprs.

type Token

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

Token is a lexeme with a line number.

func LexItems

func LexItems(ss []string) []Token

LexItems lexes a string into a slice of tokens.

Jump to

Keyboard shortcuts

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