lisp1_5

package
v0.0.0-...-b44ac9e Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT, BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const EofRune rune = -1 // Returned by Parser.SkipSpace at EOF.

Variables

This section is empty.

Functions

func Config

func Config(alwaysPrintSExprs bool)

Config configures the interpreter. The argument specifies whether output should be S-Expressions rather than lists.

Types

type Context

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

A Context holds the state of an interpreter.

func NewContext

func NewContext(depth int) *Context

NewContext returns a Context ready to execute. The argument specifies the maximum stack depth to allow, with <=0 meaning unlimited.

func (*Context) Eval

func (c *Context) Eval(expr *Expr) *Expr

Eval returns value of the expression. The result depends on the expr: - for atoms, the value of the atom - for function definitions (defn ...), the list of defined functions - for general expressions, the value of executing apply[λ[;expr];nil], that is, a vacuous lambda with expr as its body and no arguments.

func (*Context) PopStack

func (c *Context) PopStack()

PopStack resets the execution stack.

func (*Context) StackTrace

func (c *Context) StackTrace() string

StackTrace returns a printout of the execution stack. The most recent call appears first. Long stacks are trimmed in the middle.

type EOF

type EOF string // End of file on input.

Types used to signal to the outside. Both are returned through panic, which the caller is expected to recover from.

type Error

type Error string // Error on execution or parse.

Types used to signal to the outside. Both are returned through panic, which the caller is expected to recover from.

type Expr

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

Expr represents an arbitrary expression.

func Car

func Car(e *Expr) *Expr

Car implements the Lisp function CAR. Car and Cdr are functions not methods so (CADR X) is Car(Cdr(x)) not x.Cdr().Car().

func Cdr

func Cdr(e *Expr) *Expr

Cdr implements the Lisp function CDR.

func Cons

func Cons(car, cdr *Expr) *Expr

Cons implements the Lisp function CONS.

func (*Expr) SExprString

func (e *Expr) SExprString() string

SExprString returns the expression as a formatted S-Expression.

func (*Expr) String

func (e *Expr) String() string

String returns the expression as a formatted list (unless printSExpr is set).

type Parser

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

Parser is the parser for lists.

func NewParser

func NewParser(r io.RuneReader) *Parser

NewParser returns a new parser that will read from the RuneReader. Parse errors cause panics of type Error that the caller must handle.

func (*Parser) List

func (p *Parser) List() *Expr

List parses a list expression.

func (*Parser) SExpr

func (p *Parser) SExpr() *Expr

sExpr parses an S-Expression. SExpr:

Atom
Lpar SExpr Dot SExpr Rpar

func (*Parser) SkipSpace

func (p *Parser) SkipSpace() rune

SkipSpace skips leading spaces, returning the rune that follows.

func (*Parser) SkipToEndOfLine

func (p *Parser) SkipToEndOfLine()

SkipToNewline advances the input past the next newline.

type TokType

type TokType int

func (TokType) String

func (i TokType) String() string

Jump to

Keyboard shortcuts

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