lisp

package
v0.0.0-...-a19c61f Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 9 Imported by: 2

README

Shaden Lisp

TODO: Write about the overall goals of the Lisp; what we care about and what we don't.

Documentation

Overview

Package lisp provides a lisp interpreter

Index

Constants

View Source
const (
	TypeBool     = "bool"
	TypeFloat    = "float"
	TypeFunction = "function"
	TypeInt      = "int"
	TypeKeyword  = "keyword"
	TypeList     = "list"
	TypeString   = "string"
	TypeSymbol   = "symbol"
	TypeTable    = "table"
)

Lisp type names

Variables

This section is empty.

Functions

func AcceptTypes

func AcceptTypes(names ...string) string

AcceptTypes creates a formatted list of accepted types for humans

func ArgExpectError

func ArgExpectError(what string, pos int) error

ArgExpectError returns an error that indicates requirements for an argument

func CheckArityAtLeast

func CheckArityAtLeast(l List, expected int) error

CheckArityAtLeast requires the argument list to be at least certain length

func CheckArityEqual

func CheckArityEqual(l List, expected int) error

CheckArityEqual requires the argument list to be of a certain length

func Parse

func Parse(r io.Reader) (interface{}, error)

Parse parses lisp expressions in the content from an io.Reader.

Types

type EnvFunc

type EnvFunc interface {
	Name() string
	EnvFunc(*Environment, List) (interface{}, error)
}

EnvFunc is a object that can act as a function invocation in the lisp. It receives the current Environment and unevaluated arguments. This leaves it up to the function to describe how arguments should be evaluated.

type Environment

type Environment struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Environment is a registry of symbols for a lexical scope.

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment returns a new Environment.

func (*Environment) Branch

func (e *Environment) Branch() *Environment

Branch returns a new child context Environment.

func (*Environment) DefineSymbol

func (e *Environment) DefineSymbol(symbol string, v interface{}) error

DefineSymbol defines a symbol.

func (*Environment) Eval

func (e *Environment) Eval(node interface{}) (interface{}, error)

Eval evaluates expressions obtained via the Parser.

func (*Environment) GetSymbol

func (e *Environment) GetSymbol(symbol string) (interface{}, error)

GetSymbol performs a symbol lookup and returns the value if its present. If the symbol cannot be found in the current Environment context, it advances to the parent to see if can be found there.

func (*Environment) QuasiQuoteEval

func (e *Environment) QuasiQuoteEval(node interface{}) (interface{}, error)

QuasiQuoteEval is a special evaluation mode that is used in quasiquoting. Like `quote` it doesn't evaluate any expressions. However, unlike `quote` it can evaluation some nested expressions marked by the special `unquote` function invocation.

func (*Environment) SetSymbol

func (e *Environment) SetSymbol(symbol string, v interface{}) error

SetSymbol sets the value of a symbol. Like GetSymbol, it advances to parent Environments if the symbol cannot be found in the current context. If the value has not been defined yet, it errors.

func (*Environment) UnsetSymbol

func (e *Environment) UnsetSymbol(symbol string) error

UnsetSymbol removes a symbol definition. It only operates on the current context; no parent Environments will be affected.

type Func

type Func interface {
	Name() string
	Func(List) (interface{}, error)
}

Func is a object that can act as a function invocation in the lisp. It receives fully evaluated arguments.

type Keyword

type Keyword string

Keyword represents a keyword lisp type

func (Keyword) Func

func (k Keyword) Func(args List) (interface{}, error)

Func implements the Func interface. It allows Keywords to be called like functions that accept a Table as their first argument to return the associated value for that key in the Table. An optional third argument can be provided as a default value to be returned if there is no value for the key.

func (Keyword) Name

func (k Keyword) Name() string

Name returns the name used when calling Keyword as a function.

type List

type List []interface{}

List represents a list lisp type

func (List) Func

func (l List) Func(args List) (interface{}, error)

Func implements the Func interface. It allows Lists to be called like functions that accept an integer as their first argument to perform offset indexing.

func (List) Name

func (List) Name() string

Name returns the name used when calling List as a function.

type Symbol

type Symbol string

Symbol represents a symbol lisp type

type Table

type Table map[interface{}]interface{}

Table represents a table lisp type

func (Table) Func

func (t Table) Func(args List) (interface{}, error)

Func implements the Func interface. It allows Tables to be called like functions that accept a key as their first argument to return the associated value in the Table. An optional third argument can be provided as a default value to be returned if there is no value for the key.

func (Table) Name

func (Table) Name() string

Name returns the name used when calling Table as a function.

type UndefinedSymbolError

type UndefinedSymbolError struct {
	Name string
}

UndefinedSymbolError is an error returned when a symbol name cannot be found in an Environment.

func (UndefinedSymbolError) Error

func (e UndefinedSymbolError) Error() string

Directories

Path Synopsis
Package builtin provides built-in functionality for the lisp interpreter.
Package builtin provides built-in functionality for the lisp interpreter.

Jump to

Keyboard shortcuts

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