gmnlisp

package module
v0.7.18 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 17 Imported by: 3

README

Gmnlisp

Go Reference Go Test

Gmnlisp is the interpreter of ISLisp written in Go. It is developed to embbed to the applications for customizing.

Example image

Usage and Integration Guide

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/hymkor/gmnlisp"
)

func sum(ctx context.Context, w *gmnlisp.World, args []gmnlisp.Node) (gmnlisp.Node, error) {
    a, err := gmnlisp.ExpectClass[gmnlisp.Integer](ctx, w, args[0])
    if err != nil {
        return nil, err
    }
    b, err := gmnlisp.ExpectClass[gmnlisp.Integer](ctx, w, args[1])
    if err != nil {
        return nil, err
    }
    return a + b, nil
}

func main() {
    lisp := gmnlisp.New()

    lisp = lisp.Let(gmnlisp.Variables{
        gmnlisp.NewSymbol("a"): gmnlisp.Integer(1),
        gmnlisp.NewSymbol("b"): gmnlisp.Integer(2),
    })

    lisp = lisp.Flet(
        gmnlisp.Functions{
            gmnlisp.NewSymbol("sum"): &gmnlisp.Function{C: 2, F: sum},
        })

    value, err := lisp.Interpret(context.TODO(), "(sum a b)")
    if err != nil {
        fmt.Fprintln(os.Stderr, err.Error())
        return
    }
    fmt.Println(value.String())
}
$ go run examples/example.go
3
  • gmnlisp.New returns a new Lisp interpreter instance (*gmnlisp.World).
  • gmnlisp.NewSymbol constructs a symbol. Calling gmnlisp.NewSymbol("a") always returns the same value, no matter how many times it's called.
  • gmnlisp.Variables is a symbol map type. It is an alias for map[gmnlisp.Symbol]gmnlisp.Node.
    Node is the interface that all Lisp objects must implement.
  • .Let creates a new world instance with the given variable bindings (namespace).
lisp.Let(gmnlisp.Variables{
    gmnlisp.NewSymbol("a"): gmnlisp.Integer(1),
    gmnlisp.NewSymbol("b"): gmnlisp.Integer(2),
}).Interpret(context.Background(), "(c)")

is equivalent to the Lisp code: (let ((a 1) (b 2)) (c))

Type assertions

a, err := gmnlisp.ExpectClass[gmnlisp.Integer](ctx, w, x)
is similar to:
a, ok := x.(gmnlisp.Integer)

However, ExpectClass invokes the user-defined error handler if x is not of type Integer.

User-defined functions

You can register user-defined functions to the interpreter using .Flet():

lisp = lisp.Flet(
    gmnlisp.Functions{
        gmnlisp.NewSymbol("sum"): &gmnlisp.Function{C: 2, F: sum},
    })

The function definitions are passed as a gmnlisp.Functions map, where the keys are symbols and the values are Lisp function objects. There are several ways to define the function values:

  • gmnlisp.Function1(f) For a function f with the signature: func(context.Context, *gmnlisp.World, gmnlisp.Node) (gmnlisp.Node, error) Accepts one evaluated argument.

  • gmnlisp.Function2(f) For a function f with the signature: func(context.Context, *gmnlisp.World, gmnlisp.Node, gmnlisp.Node) (gmnlisp.Node, error) Accepts two evaluated arguments.

  • &gmnlisp.Function{ C: n, Min: min, Max: max, F: f } For a function f with the signature: func(context.Context, *gmnlisp.World, []gmnlisp.Node) (gmnlisp.Node, error) Accepts multiple evaluated arguments.

    • If C is non-zero, the function strictly expects C arguments.
    • If Min and Max are specified instead, the function accepts a range of arguments.
    • If all are left as zero values, argument count is not validated.

    Note: A zero value (0) means "unspecified"; negative values are not used.

  • gmnlisp.SpecialF(f) For defining special forms (macros, control structures, etc.), where arguments are passed unevaluated: func(context.Context, *gmnlisp.World, gmnlisp.Node) (gmnlisp.Node, error) All arguments are passed as a Lisp list (e.g., (list a b c) becomes &gmnlisp.Cons{Car: ..., Cdr: ...}).

    Inside this function, you can evaluate an argument manually with:

    result, err := w.Eval(ctx, x)
    

See the example in the "Usage and Integration Guide" section above for how to define and register a user function.

Supported Types

Lisp values correspond to the following Go types or constructors when embedding gmnlisp in Go applications:

Lisp Go
t gmnlisp.True
nil gmnlisp.Null
1 gmnlisp.Integer(1)
2.3 gmnlisp.Float(2.3)
"string" gmnlisp.String("string")
Symbol gmnlisp.NewSymbol("Symbol")
(cons 1 2) &gmnlisp.Cons{ Car:gmnlisp.Integer(1), Cdr:gmnlisp.Integer(2) }
#\A gmnlisp.Rune('A')

Unlike other types shown above, gmnlisp.NewSymbol(...) is a function call, not a type conversion. It returns a value of type Symbol (defined as type Symbol int), which is distinct from int. The function guarantees that the same string always maps to the same symbol value.

gmnlisp.Node is the root interface. All values that appear in Lisp code must implement this interface.

type Node interface {
    Equals(Node, EqlMode) bool
    String() string
    ClassOf() Class
}

type Class interface {
    Node
    Name() Symbol
    InstanceP(Node) bool
    Create() Node
    InheritP(Class) bool
}

type EqlMode int

const (
    STRICT EqlMode = iota // corresponds to (eql a b)
    EQUAL                 // corresponds to (equal a b)
    EQUALP                // corresponds to (equalp a b) 
)

ISLisp Compatibility

Gmnlisp implements a subset of functions defined in the ISLisp standard.

The full compatibility checklist has been moved to a separate file due to its length:
👉 ISLisp Compatibility Checklist

(Items without checkboxes are not standard functions.)

Projects Using gmnlisp

The following open-source applications embed gmnlisp to provide ISLisp-based customization and scripting:

  • lispect:
    A text-terminal automation tool similar to expect(1), powered by a subset of ISLisp.

  • smake:
    A build automation tool where Makefiles are written in S-expressions.

References

Documents (English)
Documents (Japanese)
Gmnlisp and other implementations of ISLisp
Implementation Language Windows Linux Execution Model
OK!ISLisp C Supported Supported Interpreter/Bytecode compiler
iris Go/JavaScript Supported Supported Interpreter
Easy-ISLisp C Supported Interpreter/Native Compiler
gmnlisp Go Supported Supported Interpreter

Author

hymkor (HAYAMA Kaoru)

License

MIT Licence

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAbort          = errors.New("abort")
	ErrDevisionByZero = errors.New("devision by zeor")
	ErrExpectedClass  = errors.New("expected class")
	ErrExpectedMacro  = errors.New("expected macro")
	ErrExpectedStream = errors.New("expected stream")
	ErrExpectedWriter = errors.New("expected writer")
	ErrInvalidFormat  = errors.New("invalid format")
	ErrNoMatchMethods = errors.New("no match methods")
	ErrNotSupportType = errors.New("not support type")
	ErrQuit           = errors.New("bye")

	ErrCanNotParseNumber = parser.ErrCanNotParseNumber
	ErrTooFewArguments   = ProgramError{/* contains filtered or unexported fields */}
	ErrTooManyArguments  = ProgramError{/* contains filtered or unexported fields */}
	ErrTooShortTokens    = parser.ErrTooShortTokens
	ErrIndexOutOfRange   = ProgramError{/* contains filtered or unexported fields */}
)
View Source
var BuiltInClassObject = NewAbstractClass[*BuiltInClass]("<built-in-class>")
View Source
var NewLineOnFormat = []byte{'\n'}
View Source
var ObjectClass = &BuiltInClass{
	name:      NewSymbol("<object>"),
	instanceP: func(Node) bool { return true },
	create:    func() Node { return nil },
}

Functions

func ExpectClass added in v0.7.1

func ExpectClass[T Node](ctx context.Context, w *World, v Node) (T, error)

func ExpectGeneric added in v0.6.0

func ExpectGeneric(c Callable) (*_Generic, error)

func ExpectInterface added in v0.7.1

func ExpectInterface[T Node](ctx context.Context, w *World, v Node, class Class) (T, error)

func ExpectNonReservedSymbol added in v0.7.10

func ExpectNonReservedSymbol(ctx context.Context, w *World, v Node) (_Symbol, error)

func Export added in v0.2.0

func Export(name Symbol, value Callable)

func ExportRange added in v0.2.0

func ExportRange(v Functions)

func HasValue deprecated

func HasValue(node Node) bool

Deprecated: use IsSome

func IsNonLocalExists added in v0.7.5

func IsNonLocalExists(err error) bool

func IsNone added in v0.2.1

func IsNone(node Node) bool

IsNone returns whether `node` does not have a value or not

func IsNull deprecated

func IsNull(node Node) bool

Deprecated: use IsNone

func IsSome added in v0.2.1

func IsSome(node Node) bool

IsSome returns whether `node` has a value or not

func ListToArray

func ListToArray(list Node, slice []Node) error

func MakeError added in v0.2.0

func MakeError(e error, s any) error

func MapCar

func MapCar(ctx context.Context, w *World, funcNode Node, sourceSet []Node, store func(Node)) error

func NewSymbol

func NewSymbol(s string) _Symbol

func SeqEach

func SeqEach(ctx context.Context, w *World, list Node, f func(Node) error) error

func Shift

func Shift(list Node) (Node, Node, error)

Types

type ArithmeticError added in v0.7.1

type ArithmeticError struct {
	Operation FunctionRef
	Operands  Node
	Class     Class
}

func (*ArithmeticError) ClassOf added in v0.7.1

func (e *ArithmeticError) ClassOf() Class

func (*ArithmeticError) Equals added in v0.7.1

func (e *ArithmeticError) Equals(other Node, mode EqlMode) bool

func (*ArithmeticError) Error added in v0.7.1

func (e *ArithmeticError) Error() string

func (*ArithmeticError) String added in v0.7.1

func (e *ArithmeticError) String() string

type Array added in v0.1.4

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

func (*Array) ClassOf added in v0.6.0

func (*Array) ClassOf() Class

func (*Array) Elt added in v0.1.4

func (A *Array) Elt(n int) (Node, error)

func (*Array) Equals added in v0.1.4

func (A *Array) Equals(_B Node, mode EqlMode) bool

func (*Array) FirstAndRest added in v0.7.18

func (A *Array) FirstAndRest() (Node, Node, bool)

func (Array) GoString added in v0.1.4

func (t Array) GoString() string

func (*Array) PrintTo added in v0.1.4

func (A *Array) PrintTo(w io.Writer, mode PrintMode) (int, error)

func (Array) String added in v0.1.4

func (t Array) String() string

type BigInt added in v0.7.1

type BigInt struct {
	*big.Int
}

func (BigInt) ClassOf added in v0.7.1

func (b BigInt) ClassOf() Class

func (BigInt) Equals added in v0.7.1

func (b BigInt) Equals(n Node, m EqlMode) bool

type BuiltInClass added in v0.7.17

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

func NewAbstractClass added in v0.7.17

func NewAbstractClass[T Node](name string, super ...Class) *BuiltInClass

func NewBuiltInClass added in v0.7.17

func NewBuiltInClass[T Node](name string, super ...Class) *BuiltInClass

func (*BuiltInClass) ClassOf added in v0.7.17

func (e *BuiltInClass) ClassOf() Class

func (*BuiltInClass) Create added in v0.7.17

func (e *BuiltInClass) Create() Node

func (*BuiltInClass) Equals added in v0.7.17

func (e *BuiltInClass) Equals(_other Node, _ EqlMode) bool

func (*BuiltInClass) InheritP added in v0.7.17

func (e *BuiltInClass) InheritP(c Class) bool

func (*BuiltInClass) InstanceP added in v0.7.17

func (e *BuiltInClass) InstanceP(n Node) bool

func (*BuiltInClass) Name added in v0.7.17

func (e *BuiltInClass) Name() Symbol

func (*BuiltInClass) String added in v0.7.17

func (e *BuiltInClass) String() string

type Callable

type Callable interface {
	Call(context.Context, *World, Node) (Node, error)
}

func ExpectFunction added in v0.7.0

func ExpectFunction(ctx context.Context, w *World, value Node) (Callable, error)

type Class added in v0.6.0

type Class interface {
	Node
	Name() Symbol
	InstanceP(Node) bool
	Create() Node
	InheritP(Class) bool
}

type Condition added in v0.7.17

type Condition interface {
	error
	Node
}

type Cons

type Cons struct {
	Car Node
	Cdr Node
}

func (*Cons) ClassOf added in v0.6.0

func (*Cons) ClassOf() Class

func (*Cons) Equals

func (cons *Cons) Equals(n Node, m EqlMode) bool

func (*Cons) Eval

func (cons *Cons) Eval(ctx context.Context, w *World) (Node, error)

func (*Cons) FirstAndRest

func (cons *Cons) FirstAndRest() (Node, Node, bool)

func (Cons) GoString added in v0.1.4

func (t Cons) GoString() string

func (*Cons) PrintTo

func (cons *Cons) PrintTo(w io.Writer, m PrintMode) (int, error)

func (Cons) String added in v0.1.4

func (t Cons) String() string

type Constants added in v0.7.7

type Constants map[Symbol]Node

func (Constants) Get added in v0.7.7

func (m Constants) Get(key Symbol) (Node, bool)

func (Constants) Set added in v0.7.7

func (m Constants) Set(key Symbol, value Node) error

type Continuable added in v0.7.17

type Continuable interface {
	SetContinuableString(String)
	ContinuableString() Node
}

type ControlError added in v0.7.1

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

func (ControlError) ClassOf added in v0.7.1

func (e ControlError) ClassOf() Class

func (ControlError) Equals added in v0.7.1

func (e ControlError) Equals(n Node, _ EqlMode) bool

func (ControlError) Error added in v0.7.1

func (e ControlError) Error() string

func (ControlError) String added in v0.7.1

func (e ControlError) String() string

func (ControlError) Unwrap added in v0.7.1

func (e ControlError) Unwrap() error

type DomainError added in v0.6.0

type DomainError struct {
	Object        Node
	ExpectedClass Class
	Reason        string
}

func (*DomainError) ClassOf added in v0.6.0

func (e *DomainError) ClassOf() Class

func (*DomainError) Equals added in v0.6.0

func (e *DomainError) Equals(_other Node, mode EqlMode) bool

func (*DomainError) Error added in v0.6.0

func (e *DomainError) Error() string

func (*DomainError) String added in v0.6.0

func (e *DomainError) String() string

type Dynamics added in v0.3.1

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

func (*Dynamics) Close added in v0.3.1

func (D *Dynamics) Close()

func (*Dynamics) Set added in v0.3.1

func (D *Dynamics) Set(symbol Symbol, newValue Node)

type EndOfStream added in v0.7.2

type EndOfStream struct {
	Stream Node
}

func (EndOfStream) ClassOf added in v0.7.2

func (e EndOfStream) ClassOf() Class

func (EndOfStream) Equals added in v0.7.2

func (e EndOfStream) Equals(n Node, _ EqlMode) bool

func (EndOfStream) Error added in v0.7.2

func (e EndOfStream) Error() string

func (EndOfStream) String added in v0.7.2

func (e EndOfStream) String() string

type EqlMode

type EqlMode int
const (
	STRICT EqlMode = iota // corresponds to (eql A B)
	EQUAL                 // corresponds to (equal A B)
	EQUALP                // corresponds to (equalp A B)
)

type ErrorNode

type ErrorNode struct {
	Value error
}

func (ErrorNode) ClassOf added in v0.6.0

func (ErrorNode) ClassOf() Class

func (ErrorNode) Equals

func (e ErrorNode) Equals(n Node, m EqlMode) bool

func (ErrorNode) Error added in v0.7.1

func (e ErrorNode) Error() string

func (ErrorNode) String added in v0.1.4

func (e ErrorNode) String() string

type Float

type Float float64

func (Float) Add

func (f Float) Add(ctx context.Context, w *World, n Node) (Node, error)

func (Float) ClassOf added in v0.6.0

func (Float) ClassOf() Class

func (Float) Equals

func (f Float) Equals(n Node, m EqlMode) bool

func (Float) LessThan

func (f Float) LessThan(ctx context.Context, w *World, n Node) (bool, error)

func (Float) Multi

func (f Float) Multi(ctx context.Context, w *World, n Node) (Node, error)

func (Float) String added in v0.1.4

func (f Float) String() string

func (Float) Sub

func (f Float) Sub(ctx context.Context, w *World, n Node) (Node, error)

type FuncScope added in v0.7.0

type FuncScope interface {
	Get(Symbol) (Callable, bool)
	Set(Symbol, Callable)
	Range(func(Symbol, Callable) bool)
}

type Function

type Function struct {
	C   int
	F   func(context.Context, *World, []Node) (Node, error)
	Min int
	Max int
}

func (*Function) Call

func (f *Function) Call(ctx context.Context, w *World, list Node) (Node, error)

type Function0 added in v0.7.1

type Function0 func(context.Context, *World) (Node, error)

func (Function0) Call added in v0.7.1

func (f Function0) Call(ctx context.Context, w *World, list Node) (Node, error)

type Function1 added in v0.7.1

type Function1 func(context.Context, *World, Node) (Node, error)

func (Function1) Call added in v0.7.1

func (f Function1) Call(ctx context.Context, w *World, list Node) (Node, error)

type Function2 added in v0.7.1

type Function2 func(context.Context, *World, Node, Node) (Node, error)

func (Function2) Call added in v0.7.1

func (f Function2) Call(ctx context.Context, w *World, list Node) (Node, error)

type FunctionRef added in v0.7.0

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

func (FunctionRef) ClassOf added in v0.7.0

func (f FunctionRef) ClassOf() Class

func (FunctionRef) Equals added in v0.7.0

func (f FunctionRef) Equals(other Node, mode EqlMode) bool

func (FunctionRef) GoString added in v0.7.0

func (f FunctionRef) GoString() string

func (FunctionRef) PrintTo added in v0.7.0

func (f FunctionRef) PrintTo(w io.Writer, _ PrintMode) (int, error)

func (FunctionRef) String added in v0.7.0

func (f FunctionRef) String() string

type Functions added in v0.7.0

type Functions map[Symbol]Callable

func (Functions) Get added in v0.7.0

func (m Functions) Get(key Symbol) (Callable, bool)

func (Functions) Range added in v0.7.0

func (m Functions) Range(f func(Symbol, Callable) bool)

func (Functions) Set added in v0.7.0

func (m Functions) Set(key Symbol, value Callable)

type IOFile added in v0.7.6

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

func (*IOFile) ClassOf added in v0.7.6

func (t *IOFile) ClassOf() Class

func (*IOFile) Close added in v0.7.6

func (iof *IOFile) Close() error

func (*IOFile) Column added in v0.7.6

func (iof *IOFile) Column() int

func (*IOFile) Equals added in v0.7.6

func (t *IOFile) Equals(Node, EqlMode) bool

func (*IOFile) FilePosition added in v0.7.6

func (i *IOFile) FilePosition() (int64, error)

func (*IOFile) IsClosed added in v0.7.6

func (iof *IOFile) IsClosed() bool

func (*IOFile) QueryStreamReady added in v0.7.6

func (i *IOFile) QueryStreamReady() (Node, error)

func (*IOFile) Read added in v0.7.6

func (iof *IOFile) Read(b []byte) (int, error)

func (*IOFile) ReadByte added in v0.7.6

func (iof *IOFile) ReadByte() (byte, error)

func (*IOFile) ReadRune added in v0.7.6

func (iof *IOFile) ReadRune() (rune, int, error)

func (*IOFile) SetFilePosition added in v0.7.6

func (i *IOFile) SetFilePosition(n int64) (int64, error)

func (*IOFile) String added in v0.7.6

func (t *IOFile) String() string

func (*IOFile) UnreadRune added in v0.7.6

func (iof *IOFile) UnreadRune() error

func (*IOFile) Write added in v0.7.6

func (iof *IOFile) Write(b []byte) (int, error)

type Integer

type Integer int64

func (Integer) Add

func (i Integer) Add(ctx context.Context, w *World, n Node) (Node, error)

func (Integer) ClassOf added in v0.6.0

func (i Integer) ClassOf() Class

func (Integer) Equals

func (i Integer) Equals(n Node, m EqlMode) bool

func (Integer) LessThan

func (i Integer) LessThan(ctx context.Context, w *World, n Node) (bool, error)

func (Integer) Multi

func (i Integer) Multi(ctx context.Context, w *World, n Node) (Node, error)

func (Integer) String added in v0.1.4

func (i Integer) String() string

func (Integer) Sub

func (i Integer) Sub(ctx context.Context, w *World, n Node) (Node, error)

type Keyword

type Keyword int

func NewKeyword added in v0.3.0

func NewKeyword(name string) Keyword

func (Keyword) ClassOf added in v0.6.0

func (Keyword) ClassOf() Class

func (Keyword) Equals

func (k Keyword) Equals(n Node, m EqlMode) bool

func (Keyword) String added in v0.1.4

func (k Keyword) String() string

type LispString added in v0.1.4

type LispString struct {
	S string
	// contains filtered or unexported fields
}

func (*LispString) Call added in v0.1.4

func (L *LispString) Call(ctx context.Context, w *World, n Node) (Node, error)

func (*LispString) Eval added in v0.1.4

func (L *LispString) Eval(ctx context.Context, w *World) (Node, error)

type ListBuilder

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

func (*ListBuilder) Add

func (L *ListBuilder) Add(ctx context.Context, w *World, n Node) error

func (*ListBuilder) Sequence

func (L *ListBuilder) Sequence() Node

type Node

type Node interface {
	Equals(Node, EqlMode) bool
	String() string
	ClassOf() Class
}
var Null Node = _NullType{}
var True Node = _TrueType{}

func Assoc

func Assoc(ctx context.Context, w *World, key Node, list Node) (Node, error)

func ExpectList added in v0.7.16

func ExpectList(ctx context.Context, w *World, arg Node) (Node, error)

func List

func List(nodes ...Node) Node

func NReverse

func NReverse(ctx context.Context, w *World, list Node) (Node, error)

func NewVector

func NewVector(ctx context.Context, w *World, args ...Node) Node

func Progn

func Progn(ctx context.Context, w *World, n Node) (value Node, err error)

func ReadAll

func ReadAll(rs io.RuneScanner) ([]Node, error)

func ReadNode

func ReadNode(rs io.RuneScanner) (Node, error)

func Reverse

func Reverse(list Node) (Node, error)

func UnevalList added in v0.7.1

func UnevalList(list ...Node) Node

type Pair

type Pair struct {
	Key   Symbol
	Value Node
}

func (*Pair) Get

func (m *Pair) Get(key Symbol) (Node, bool)

func (*Pair) Range added in v0.3.0

func (m *Pair) Range(f func(Symbol, Node) bool)

func (*Pair) Set

func (m *Pair) Set(key Symbol, value Node) error

type ParseError added in v0.7.1

type ParseError struct {
	ExpectedClass Class
	// contains filtered or unexported fields
}

func (*ParseError) ClassOf added in v0.7.1

func (p *ParseError) ClassOf() Class

func (*ParseError) Equals added in v0.7.1

func (p *ParseError) Equals(other Node, m EqlMode) bool

func (*ParseError) Error added in v0.7.1

func (p *ParseError) Error() string

func (*ParseError) String added in v0.7.1

func (p *ParseError) String() string

type PrintMode

type PrintMode int
const (
	PRINT PrintMode = iota // AS S-Expression
	PRINC                  // AS IS
)

type ProgramError added in v0.7.1

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

func (ProgramError) ClassOf added in v0.7.1

func (e ProgramError) ClassOf() Class

func (ProgramError) Equals added in v0.7.1

func (e ProgramError) Equals(n Node, _ EqlMode) bool

func (ProgramError) Error added in v0.7.1

func (e ProgramError) Error() string

func (ProgramError) String added in v0.7.1

func (e ProgramError) String() string

func (ProgramError) Unwrap added in v0.7.1

func (e ProgramError) Unwrap() error

type Reserved added in v0.7.10

type Reserved int

func NewReserved added in v0.7.10

func NewReserved(name string) Reserved

func (Reserved) ClassOf added in v0.7.10

func (_ Reserved) ClassOf() Class

func (Reserved) Equals added in v0.7.10

func (r Reserved) Equals(n Node, m EqlMode) bool

func (Reserved) Eval added in v0.7.10

func (r Reserved) Eval(_ context.Context, w *World) (Node, error)

func (Reserved) Id added in v0.7.10

func (r Reserved) Id() int

func (Reserved) OriginalString added in v0.7.10

func (s Reserved) OriginalString() string

func (Reserved) String added in v0.7.10

func (r Reserved) String() string

type Rune

type Rune rune

func (Rune) Add

func (r Rune) Add(ctx context.Context, w *World, n Node) (Node, error)

func (Rune) ClassOf added in v0.6.0

func (Rune) ClassOf() Class

func (Rune) Equals

func (r Rune) Equals(n Node, m EqlMode) bool

func (Rune) GoString added in v0.1.4

func (r Rune) GoString() string

func (Rune) String added in v0.1.4

func (r Rune) String() string

func (Rune) Sub

func (r Rune) Sub(ctx context.Context, w *World, n Node) (Node, error)

type Scope

type Scope interface {
	Get(Symbol) (Node, bool)
	Set(Symbol, Node) error
	Range(func(Symbol, Node) bool)
}

type SeqBuilder

type SeqBuilder interface {
	Add(context.Context, *World, Node) error
	Sequence() Node
}

type Sequence

type Sequence interface {
	FirstAndRest() (Node, Node, bool)
	Node
}

type SimpleError added in v0.7.11

type SimpleError struct {
	FormatString    Node
	FormatArguments Node
	// contains filtered or unexported fields
}

func (*SimpleError) ClassOf added in v0.7.11

func (s *SimpleError) ClassOf() Class

func (*SimpleError) ContinuableString added in v0.7.17

func (s *SimpleError) ContinuableString() Node

func (*SimpleError) Equals added in v0.7.11

func (s *SimpleError) Equals(other Node, m EqlMode) bool

func (*SimpleError) Error added in v0.7.16

func (s *SimpleError) Error() string

func (*SimpleError) SetContinuableString added in v0.7.17

func (s *SimpleError) SetContinuableString(cs String)

func (*SimpleError) String added in v0.7.11

func (s *SimpleError) String() string

type SpecialF

type SpecialF func(context.Context, *World, Node) (Node, error)

func (SpecialF) Call

func (f SpecialF) Call(ctx context.Context, w *World, n Node) (Node, error)

type StorageExhausted added in v0.7.1

type StorageExhausted struct{}

func (StorageExhausted) ClassOf added in v0.7.1

func (s StorageExhausted) ClassOf() Class

func (StorageExhausted) Equals added in v0.7.1

func (s StorageExhausted) Equals(n Node, _ EqlMode) bool

func (StorageExhausted) Error added in v0.7.1

func (s StorageExhausted) Error() string

func (StorageExhausted) String added in v0.7.1

func (s StorageExhausted) String() string

type StreamError added in v0.7.2

type StreamError struct {
	Stream Node
}

func (StreamError) ClassOf added in v0.7.2

func (s StreamError) ClassOf() Class

func (StreamError) Equals added in v0.7.2

func (s StreamError) Equals(other Node, m EqlMode) bool

func (StreamError) Error added in v0.7.2

func (s StreamError) Error() string

func (StreamError) String added in v0.7.2

func (s StreamError) String() string

type String

type String string

func (String) Add added in v0.1.4

func (s String) Add(ctx context.Context, w *World, n Node) (Node, error)

func (String) ClassOf added in v0.6.0

func (String) ClassOf() Class

func (String) EachRune added in v0.1.4

func (s String) EachRune(f func(Rune) error) error

func (String) Equals added in v0.1.4

func (s String) Equals(n Node, m EqlMode) bool

func (String) FirstAndRest added in v0.1.4

func (s String) FirstAndRest() (Node, Node, bool)

func (String) GoString added in v0.1.4

func (s String) GoString() string

func (String) LessThan added in v0.1.4

func (s String) LessThan(ctx context.Context, w *World, n Node) (bool, error)

func (String) String added in v0.1.4

func (s String) String() string

type StringBuilder

type StringBuilder struct {
	strings.Builder
}

func (*StringBuilder) Add added in v0.1.4

func (S *StringBuilder) Add(ctx context.Context, w *World, n Node) error

func (*StringBuilder) ClassOf added in v0.6.0

func (*StringBuilder) ClassOf() Class

func (*StringBuilder) Close added in v0.7.13

func (S *StringBuilder) Close() error

func (*StringBuilder) Column added in v0.7.6

func (S *StringBuilder) Column() int

func (*StringBuilder) Equals added in v0.1.4

func (t *StringBuilder) Equals(other Node, _ EqlMode) bool

func (StringBuilder) GoString added in v0.1.4

func (S StringBuilder) GoString() string

func (*StringBuilder) RawWriter added in v0.7.17

func (t *StringBuilder) RawWriter() io.Writer

func (*StringBuilder) Sequence added in v0.1.4

func (S *StringBuilder) Sequence() Node

func (*StringBuilder) String added in v0.7.6

func (S *StringBuilder) String() string

type StringReader added in v0.7.6

type StringReader struct {
	*strings.Reader
}

func (StringReader) ClassOf added in v0.7.6

func (sr StringReader) ClassOf() Class

func (StringReader) Close added in v0.7.13

func (sr StringReader) Close() error

func (StringReader) Equals added in v0.7.6

func (sr StringReader) Equals(other Node, _ EqlMode) bool

func (StringReader) QueryStreamReady added in v0.7.6

func (sr StringReader) QueryStreamReady() (Node, error)

func (StringReader) String added in v0.7.6

func (sr StringReader) String() string

type Symbol

type Symbol interface {
	Id() int
	Node
	OriginalString() string
}

func ExpectSymbol added in v0.7.0

func ExpectSymbol(ctx context.Context, w *World, v Node) (Symbol, error)

type Uneval added in v0.6.0

type Uneval struct {
	Node
}

func (Uneval) Eval added in v0.6.0

func (u Uneval) Eval(ctx context.Context, w *World) (Node, error)

type Variables

type Variables map[Symbol]Node

func (Variables) Get

func (m Variables) Get(key Symbol) (Node, bool)

func (Variables) Range added in v0.3.0

func (m Variables) Range(f func(Symbol, Node) bool)

func (Variables) Set

func (m Variables) Set(key Symbol, value Node) error

type VectorBuilder

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

func (*VectorBuilder) Add

func (v *VectorBuilder) Add(ctx context.Context, w *World, value Node) error

func (*VectorBuilder) Sequence

func (v *VectorBuilder) Sequence() Node

type World

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

func New

func New() *World

func (*World) Assert

func (w *World) Assert(equation string, expect Node) string

func (*World) DefineGlobal

func (w *World) DefineGlobal(name Symbol, value Node)

DefineGlobal implements (defglobal) of ISLisp or (defparameter) of CommonLisp.

func (*World) Dynamic added in v0.3.1

func (w *World) Dynamic(name Symbol) Node

func (*World) Errout

func (w *World) Errout() io.Writer

func (*World) Eval added in v0.7.1

func (w *World) Eval(ctx context.Context, node Node) (Node, error)

func (*World) Flet added in v0.7.0

func (w *World) Flet(scope FuncScope) *World

func (*World) FuncRange added in v0.7.16

func (W *World) FuncRange(f func(Symbol, Callable) bool)

func (*World) Get

func (w *World) Get(name Symbol) (Node, error)

func (*World) GetFunc added in v0.7.0

func (w *World) GetFunc(name Symbol) (Callable, error)

func (*World) Interpret

func (w *World) Interpret(ctx context.Context, code string) (Node, error)

func (*World) InterpretBytes

func (w *World) InterpretBytes(ctx context.Context, code []byte) (Node, error)

func (*World) InterpretNodes

func (w *World) InterpretNodes(ctx context.Context, ns []Node) (Node, error)

func (*World) Let

func (w *World) Let(scope Scope) *World

func (*World) NewDynamics added in v0.3.1

func (w *World) NewDynamics() *Dynamics

func (*World) Range added in v0.3.0

func (W *World) Range(f func(Symbol, Node) bool)

func (*World) Set

func (w *World) Set(name Symbol, value Node) error

func (*World) SetErrout

func (w *World) SetErrout(writer io.Writer)

func (*World) SetStdout

func (w *World) SetStdout(writer io.Writer)

func (*World) ShiftAndEvalCar

func (w *World) ShiftAndEvalCar(ctx context.Context, list Node) (Node, Node, error)

func (*World) Stdin

func (w *World) Stdin() _Reader

func (*World) Stdout

func (w *World) Stdout() io.Writer

type Writer added in v0.7.6

type Writer interface {
	io.Writer
	Node
}

type WriterStream added in v0.7.17

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

func NewWriterStream added in v0.7.17

func NewWriterStream(w io.Writer) *WriterStream

func (WriterStream) ClassOf added in v0.7.17

func (WriterStream) ClassOf() Class

func (*WriterStream) Column added in v0.7.17

func (w *WriterStream) Column() int

func (WriterStream) Equals added in v0.7.17

func (t WriterStream) Equals(Node, EqlMode) bool

func (WriterStream) RawWriter added in v0.7.17

func (t WriterStream) RawWriter() io.Writer

func (WriterStream) String added in v0.7.17

func (t WriterStream) String() string

func (*WriterStream) Write added in v0.7.17

func (w *WriterStream) Write(p []byte) (int, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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