gmnlisp

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 14 Imported by: 2

README

GoDoc

Gmnlisp

The Gmnlisp is a small Lisp implementation in Go. The functions are the subset of ISLisp's. It is developed to embbed to the applications for customizing.

Example image

Install

Download the binary package from Releases and extract the executable.

via golang-installer
go install github.com/hymkor/gmnlisp/cmd/gmnlisp@latest
via scoop-installer
scoop install https://raw.githubusercontent.com/hymkor/gmnlisp/master/gmnlisp.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install gmnlisp

Examples

1. Execute Lisp code in string with parameters
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/hymkor/gmnlisp"
)

func main() {
    lisp := gmnlisp.New()
    lisp = lisp.Let(gmnlisp.Variables{
        gmnlisp.NewSymbol("a"): gmnlisp.Integer(1),
        gmnlisp.NewSymbol("b"): gmnlisp.Integer(2),
    })
    value, err := lisp.Interpret(context.TODO(), "(+ a b)")
    if err != nil {
        fmt.Fprintln(os.Stderr, err.Error())
        return
    }
    value.PrintTo(os.Stdout, gmnlisp.PRINT)
    fmt.Println()
}
$ go run examples/example1.go
3
  • gmnlisp.New returns the new Lisp interpretor instance (*gmnlisp.World).
  • gmnlisp.NewSymbol is the symbol constructor. gmnlisp.NewSymbol("a") always returns the same value no matter how many times you call it.
  • gmnlisp.Variables is the symbol-map type. It is the alias of map[gmnlisp.Symbol]gmnlisp.Node. Node is the interface-type that all objects in the Lisp have to implement.
  • .Let makes a new instance including the given namespace.
lisp.Let(gmnlisp.Variables{
        gmnlisp.NewSymbol("a"): gmnlisp.Integer(1),
        gmnlisp.NewSymbol("b"): gmnlisp.Integer(2),
    }).Interpret(context.Background(),"(c)")

is same as (let ((a 1) (b 1)) (c))

2. Execute Lisp-code and give call-back function written in Go
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, ok := args[0].(gmnlisp.Integer)
    if !ok {
        return nil, fmt.Errorf("expect integer: %#v", args[0])
    }
    b, ok := args[1].(gmnlisp.Integer)
    if !ok {
        return nil, fmt.Errorf("expect integer: %#v", args[1])
    }
    return gmnlisp.Integer(a + b), nil
}

func main() {
    lisp := gmnlisp.New()
    lisp = lisp.Let(
        gmnlisp.Variables{
            gmnlisp.NewSymbol("sum"): &gmnlisp.Function{C: 2, F: sum},
        })

    result, err := lisp.Interpret(context.Background(), `(sum 1 2)`)
    if err != nil {
        fmt.Fprintln(os.Stderr, err.Error())
        return
    }
    fmt.Printf("(sum 1 2)=%v\n", result)
}
$ go run examples/example2.go
(sum 1 2)=3

The user defined normal functions have to get the three parameters.

  • The 1st: context.Context that is given to the method .Interpret()
  • The 2nd: *gmnlisp.World on which the instance runs.
  • The 3rd: []gmnlisp.Node the parameters given by caller. They are already evaluated.

gmnlisp.Function wraps the normal function as Lisp object.

  • F: the function itself
  • C: when the number of the parameter is not same as this, the error will be raised. If it does not have to be checked, omit it.

To get unevaluted parameters, the function's definition should be as below.

func FUNCNAME(c context.Context,w *World,args Node)(Node,error){...}
  • The parameters are given as a list not an array.
  • Use gmnlisp.SpecialF(FUNCNAME) instead of gmnlisp.Function{F:FUNCNAME}

Support Types

Type(Lisp) Type(Go)
t gmnlisp._TrueType
nil gmnlisp._NullType
<integer> gmnlisp.Integer == int64
<float> gmnlisp.Float == float64
<string> gmnlisp.String == string
<symbol> gmnlisp.Symbol == int
<cons> *gmnlisp.Cons == struct{ Car,Cdr: gmnlisp.Node }
<character> gmnlisp.Rune == rune
(keyword) gmnlisp.Keyword
(array) *gmnlisp.Array
(hashtable) gmnlisp._Hash == map[gmnlisp.Node]gmnlisp.Node

gmnlisp.Node is the root interface. All objects used in Lisp code have to satisfy it.

gmnlisp.Symbol is the unique number associated to string.

  • string to gmnlisp.Symbol
    • sbl := gmnlisp.NewSymbol("foo")
  • Symbol to string
    • sbl.String()

Support functions

Gmnlisp's functions are subset of ISLisp.

1 Scope, Conventions and Compliance
2 Classes
3 Scope and Extent
3.1 The lexical Principle
3.2 Scope of Identifiers
3.3 Some Specific Scope Rules
3.4 Extent
  • block
  • dynamic-let
  • flet
  • for
  • labels
  • let
  • let*
  • tagbody
  • with-error-output
  • with-open-input-file
  • with-open-io-file
  • with-open-output-file
  • with-standard-input
  • with-standard-output
4 Forms and Evaluation
4.1 Forms
4.2 Function Application Forms
4.3 Special Forms
  • and
  • assure
  • block
  • case
  • case-using
  • catch
  • class
  • cond
  • convert
  • dynamic
  • dynamic-let
  • flet
  • for
  • function
    • &rest
    • #'FUNCTION
  • go
  • if
  • ignore-errors
  • labels
  • lambda
  • let
  • let*
  • or
  • progn
  • quote
  • return-from
  • setf
  • setq
  • tagbody
  • the
  • throw
  • unwind-protect
  • while
  • with-error-output
  • with-handler
  • with-open-input-file
  • with-open-io-file
  • with-open-output-file
  • with-standard-input
  • with-standard-output
4.4 Defining Forms
  • defclass
    • :initarg
    • :initform
    • :accessor
    • :reader
    • :writer
    • :boundp
  • defconstant
  • defdynamic
  • defgeneric
  • defglobal
  • defmacro
  • defmethod
  • defun
4.5 Macro Forms
4.6 The Evaluation Model
4.7 Functions
  • functionp
  • function
  • lambda
  • labels
  • flet
  • apply
  • funcall
4.8 Defining Operators
  • defconstant
  • defglobal
  • defdynamic
  • defun
5 Predicates
5.1 Boolean Values
  • t
  • nil
5.2 Class Predicates
  • basic-array-p
  • basic-array*-p
  • basic-vector-p
  • characterp
  • consp
  • floatp
  • functionp
  • general-array*-p
  • general-vector-p
  • generic-function-p
  • integerp
  • listp
  • null
  • numberp
  • streamp
  • stringp
  • symbolp
  • Non-standard functions
    • atom OBJ
    • evenp OBJ
    • minusp OBJ
    • oddp OBJ
    • plusp OBJ
    • zerop OBJ
5.3 Equality
  • eq
  • eql
  • equal
  • Non-standard functions
    • equalp
5.4 Logical Connectives
  • not
  • and
  • or
6 Control Structure
6.1 Constants
  • (quote)
  • 'OBJ
6.2 Variables
  • setq
  • setf
  • let
  • let*
6.3 Dynamic Variables
  • dynamic
  • dynamic-let
6.4 Conditional Expressions
  • if
  • cond
  • case
  • case-using
  • Non-standard functions
    • when
    • unless
6.5 Sequencing Forms
  • progn
  • Non-standard functions
    • prog1
    • prog2
6.6 Iteration
  • while
  • for
  • Non-standard functions
    • dolist
    • dotimes
6.7 Non-Local Exits
6.7.1 Establishing and Invoking Non-Local Exits
  • block
  • return-from
  • catch
  • throw
  • tagbody
  • go
  • Non-standard functions
    • return
6.7.2 Assuring Data Consistency during Non-Local Exists
  • unwind-protect
7 Objects
7.1 Defining Classes
  • defclass
  • generic-function-p
7.2 Generic Functions
7.2.1 Defining Generic Functions
  • defgeneric
7.2.2 Defining Methods for Generic Functions
  • defmethod
7.3 Calling Generic Functions
7.3.4 Calling More General Methods
  • call-next-method
  • next-method-p
7.4 Object Creation and Initialization
  • create
    • :initarg
    • :initform
    • :accessor
    • :reader
    • :writer
    • :boundp
  • initialize-object
7.5 Class Enquiry
  • class-of
  • instancep
  • subclassp
  • class
8 Macros
  • defmacro
  • 'form
  • `form
  • ,@form
9 Declarations and Coercions
  • the
  • assure
  • convert
    • (convert OBJ <float>)
    • (convert OBJ <integer>)
    • (convert OBJ <list>)
    • (convert OBJ <string>)
    • (convert OBJ <symbol>)
10 Symbol classes
  • symbolp
10.2 Symbol Properties
  • property
  • set-property , setf
  • remove-property
10.3 Unnamed Symbols
  • gensym
11 Number class
11.1 Number class
  • numberp
  • parse-number
  • =
  • /=
  • >=
  • <=
  • >
  • <
  • +
  • *
  • -
  • reciproca1
  • quotient
  • max
  • min
  • abs
  • exp
  • log
  • expt
  • sqrt
  • sin
  • cos
  • tan
  • atan
  • atan2
  • sinh
  • cosh
  • tanh
  • atanh
  • Non-standard functions
    • 1+
    • 1-
    • incf
    • decf
11.2 Float class
  • *pi*
  • *most-positive-float*
  • *most-negative-float*
  • floatp
  • float
  • floor
  • ceiling
  • truncate
  • round
11.3 Integer class
  • integerp
  • div
  • mod
  • gcd
  • lcm
  • isqrt
  • Non-standard functions
    • rem
    • most-postive-fixnum
    • most-negative-fixnum
12 Character class
  • characterp
  • char=
  • char/=
  • char<
  • char>
  • char<=
  • char>=
13 List class
13.1 Cons
  • consp
  • cons OBJ
  • car
  • cdr
  • set-car, (setf (car CONS) OBJ)
  • set-cdr, (setf (cdr CONS) OBJ)
13.2 Null class
  • null
13.3 List operations
  • listp
  • create-list
  • list
  • reverse
  • nreverse
  • append
  • member
  • mapcar
  • mapc
  • maplist
  • mapl
  • mapcan
  • mapcon
  • assoc
  • Non-standard functions
    • last
14 Arrays
14.1 Array Classes
14.2 General Arrays
14.3 Array Operations
  • basic-array-p
  • basic-array*-p
  • general-array*-p
  • create-array
  • aref
  • garef
  • set-aref , (setf (aref BASIC-ARRAY Z*) OBJ)
  • set-garef , (setf (garef BASIC-ARRAY Z*) OBJ)
  • array-dimensions
  • #(...) , #2a((...) (...)) , #3a(((.. ..))) ...
15 Vector
  • basic-vector-p
  • general-vector-p
  • create-vector
  • vector
16 String class
  • stringp
  • create-string
  • string=
  • string/=
  • string<
  • string>
  • string>=
  • string<=
  • char-index
  • string-index
  • string-append
17 Sequence Functions
  • length
  • elt
  • set-elt, (setf (elt SEQ Z) OBJ)
  • subseq
  • map-into
18 Stream class
  • streamp
  • open-stream-p
  • input-stream-p
  • output-stream-p
  • standard-input
  • standard-output
  • error-output
  • with-standard-input
  • with-standard-output
  • with-error-output
18.1 Streams to files
  • open-input-file
  • open-output-file
  • open-io-file
  • with-open-input-file
  • with-open-output-file
  • with-open-io-file
  • close
  • finish-output
18.2 Other streams
  • create-string-input-stream
  • create-string-output-stream
  • get-output-stream-string
19 Input and Output
19.1 Argument conventions for input functions
  • read
  • read-char
  • preview-char
  • read-line
  • stream-ready-p
  • format
  • format-char
  • format-float
  • format-fresh-line
  • format-integer
  • format-object
  • format-tab
19.2 Charactoer I/O
19.3 Binary I/O
  • read-byte
  • write-byte
20 Files
  • probe-file
  • file-position
  • set-file-position
  • file-length
21 Condition System
21.1 Condition
21.2 Signaling and handling condtions
21.2.1 Operations relating to condition signaling
  • error
  • cerror
  • signal-condition
21.2.2 Operations relating to condition handling
  • ignore-error
  • report-condition
  • condition-continuable
  • with-handler
21.3 Data associated with condition classes
21.3.1 Arithmetic errors
  • arithmetic-error-operands
21.3.2 Domain errors
  • domain-error-object
  • domain-error-expected-class
21.3.3 Parse errors
  • parse-error-string
  • parse-error-expected-class
21.3.4 Simple errors
  • simple-error-format-string
  • simple-error-format-arguments
21.3.5 Stream errors
  • stream-error-stream
  • undefined-entity-name
  • undefined-entity-namespace
21.4 Error identification
  • arity-error
    :
  • undefined-function
22 Miscellaneous
  • identify
  • get-universal-time
  • get-internal-real-time
  • get-internal-run-time
  • internal-time-units-per-second
Regular Expression
import (
    _ "github.com/hymkor/gmnlisp/regexp"
)

is required.

  • (=~ REGEXP STRING)

compatible with "regexp".Regexp.FindAllStringSubmatch

(let ((m (=~ "a(x*)b" "-axxb-ab-")))
  (format t "ALL=~s~%" m)
  (format t "0,0=~s~%" (elt m 0 0))
  (format t "0,1=~s~%" (elt m 0 1))
  (format t "1,0=~s~%" (elt m 1 0))
  (format t "1,1=~s~%" (elt m 1 1))
  )
ALL=(("axxb" "xx") ("ab" ""))
0,0="axxb"
0,1="xx"
1,0="ab"
1,1=""
  • (=~i REGEXP STRING)

compatible with "regexp".Regexp.FindAllStringSubmatchIndex

(let ((m (=~i "a(x*)b" "-axxb-ab-")))
  (format t "INDEXES=~s~%" m)
  )
INDEXES=((1 5 2 4) (6 8 7 7))
Hash-table
(let ((h1 (make-hash-table)))
  (setf (gethash 'width h1) 600)
  (gethash 'width h1)
  (hash-table-count h1)
  (remhash 'width h1)
  (clrhash h1)
  )
Quit
  • (exit)
  • (quit)
  • (abort)

References

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDevisionByZero       = errors.New("devision by zeor")
	ErrExpectedCharacter    = errors.New("expected character")
	ErrExpectedCons         = errors.New("expected CONS")
	ErrExpectedFunction     = errors.New("expected function")
	ErrExpectedNumber       = errors.New("expected number")
	ErrExpectedReader       = errors.New("expected Reader")
	ErrExpectedSequence     = errors.New("expected Sequence")
	ErrExpectedString       = errors.New("expected string")
	ErrExpectedSymbol       = errors.New("expected symbol")
	ErrExpectedSymbolOrList = errors.New("expected symbol or list")
	ErrExpectedKeyword      = errors.New("expected keyword")
	ErrExpectedWriter       = errors.New("expected Writer")
	ErrIndexOutOfRange      = errors.New("index out of range")
	ErrInvalidFormat        = errors.New("invalid format")
	ErrNotSupportType       = errors.New("not support type")
	ErrQuit                 = errors.New("bye")
	ErrAbort                = errors.New("abort")
	ErrVariableUnbound      = errors.New("unbound variable")
	ErrExpectedArray        = errors.New("expected array")
	ErrExpectedMacro        = errors.New("expected macro")

	ErrTooFewArguments   = parser.ErrTooFewArguments
	ErrTooManyArguments  = parser.ErrTooManyArguments
	ErrCanNotParseNumber = parser.ErrCanNotParseNumber
	ErrTooShortTokens    = parser.ErrTooShortTokens
)
View Source
var ErrExpectedHash = errors.New("expected Hash-table")
View Source
var UseStrict = true

Functions

func Export added in v0.2.0

func Export(name Symbol, value Node)

func ExportRange added in v0.2.0

func ExportRange(v Variables)

func HasValue deprecated

func HasValue(node Node) bool

Deprecated: use IsSome

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 SeqEach

func SeqEach(list Node, f func(Node) error) error

func Shift

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

Types

type Array added in v0.1.4

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

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) Eval added in v0.1.4

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

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 Callable

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

type CanKnowLastOutput added in v0.2.1

type CanKnowLastOutput interface {
	IsLastOutputLf() bool
}

type Cons

type Cons struct {
	Car Node
	Cdr Node
}

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 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 EqlMode

type EqlMode int
const (
	STRICT EqlMode = iota
	EQUAL
	EQUALP
)

type ErrEarlyReturns

type ErrEarlyReturns struct {
	Value Node
	Name  Symbol
}

func (*ErrEarlyReturns) Error

func (e *ErrEarlyReturns) Error() string

type ErrThrown

type ErrThrown struct {
	Value   Node
	TagForm Node
}

func (*ErrThrown) Error

func (e *ErrThrown) Error() string

type ErrorNode

type ErrorNode struct {
	Value error
}

func (*ErrorNode) Equals

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

func (*ErrorNode) Eval

func (e *ErrorNode) Eval(context.Context, *World) (Node, error)

func (ErrorNode) GoString added in v0.1.4

func (t ErrorNode) GoString() string

func (*ErrorNode) PrintTo

func (e *ErrorNode) PrintTo(w io.Writer, m PrintMode) (int, error)

func (ErrorNode) String added in v0.1.4

func (t ErrorNode) String() string

type Float

type Float float64

func (Float) Add

func (f Float) Add(n Node) (Node, error)

func (Float) Divide

func (f Float) Divide(n Node) (Node, error)

func (Float) Equals

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

func (Float) Eval

func (f Float) Eval(context.Context, *World) (Node, error)

func (Float) GoString added in v0.1.4

func (t Float) GoString() string

func (Float) LessThan

func (f Float) LessThan(n Node) (bool, error)

func (Float) Multi

func (f Float) Multi(n Node) (Node, error)

func (Float) PrintTo

func (f Float) PrintTo(w io.Writer, m PrintMode) (int, error)

func (Float) String added in v0.1.4

func (t Float) String() string

func (Float) Sub

func (f Float) Sub(n Node) (Node, error)

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)

func (*Function) Equals

func (f *Function) Equals(n Node, m EqlMode) bool

func (*Function) Eval

func (f *Function) Eval(context.Context, *World) (Node, error)

func (Function) GoString added in v0.1.4

func (t Function) GoString() string

func (*Function) PrintTo

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

func (Function) String added in v0.1.4

func (t Function) String() string

type Integer

type Integer int64

func (Integer) Add

func (i Integer) Add(n Node) (Node, error)

func (Integer) Divide

func (i Integer) Divide(n Node) (Node, error)

func (Integer) Equals

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

func (Integer) Eval

func (i Integer) Eval(context.Context, *World) (Node, error)

func (Integer) GoString added in v0.1.4

func (t Integer) GoString() string

func (Integer) LessThan

func (i Integer) LessThan(n Node) (bool, error)

func (Integer) Multi

func (i Integer) Multi(n Node) (Node, error)

func (Integer) PrintTo

func (i Integer) PrintTo(w io.Writer, m PrintMode) (int, error)

func (Integer) String added in v0.1.4

func (t Integer) String() string

func (Integer) Sub

func (i Integer) Sub(n Node) (Node, error)

type Keyword

type Keyword int

func NewKeyword added in v0.3.0

func NewKeyword(name string) Keyword

func (Keyword) Equals

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

func (Keyword) Eval

func (k Keyword) Eval(context.Context, *World) (Node, error)

func (Keyword) GoString added in v0.1.4

func (t Keyword) GoString() string

func (Keyword) PrintTo

func (k Keyword) PrintTo(w io.Writer, m PrintMode) (int, error)

func (Keyword) String added in v0.1.4

func (t 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) Equals added in v0.1.4

func (L *LispString) Equals(_other Node, m EqlMode) bool

func (*LispString) Eval added in v0.1.4

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

func (LispString) GoString added in v0.1.4

func (t LispString) GoString() string

func (*LispString) PrintTo added in v0.1.4

func (L *LispString) PrintTo(w io.Writer, m PrintMode) (int, error)

func (LispString) String added in v0.1.4

func (t LispString) String() string

type ListBuilder

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

func (*ListBuilder) Add

func (L *ListBuilder) Add(n Node) error

func (*ListBuilder) Sequence

func (L *ListBuilder) Sequence() Node

type Node

type Node interface {
	Eval(context.Context, *World) (Node, error)
	Equals(Node, EqlMode) bool
	PrintTo(io.Writer, PrintMode) (int, error)
	String() string
	GoString() string
}
var Null Node = _NullType{}
var True Node = _TrueType{}

func Assoc

func Assoc(key Node, list Node) (Node, error)

func List

func List(nodes ...Node) Node

func NReverse

func NReverse(list Node) (Node, error)

func NewVector

func NewVector(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)

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) error) error

func (*Pair) Set

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

type PrintMode

type PrintMode int
const (
	PRINT PrintMode = iota
	PRINC
)

type Rune

type Rune rune

func (Rune) Add

func (r Rune) Add(n Node) (Node, error)

func (Rune) Equals

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

func (Rune) Eval

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

func (Rune) GoString added in v0.1.4

func (t Rune) GoString() string

func (Rune) PrintTo

func (r Rune) PrintTo(w io.Writer, m PrintMode) (int, error)

func (Rune) String added in v0.1.4

func (t Rune) String() string

func (Rune) Sub

func (r Rune) Sub(n Node) (Node, error)

type Scope

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

type SeqBuilder

type SeqBuilder interface {
	Add(Node) error
	Sequence() Node
}

type Sequence

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

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)

func (SpecialF) Equals

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

func (SpecialF) Eval

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

func (SpecialF) GoString added in v0.1.4

func (t SpecialF) GoString() string

func (SpecialF) PrintTo

func (SpecialF) PrintTo(w io.Writer, m PrintMode) (int, error)

func (SpecialF) String added in v0.1.4

func (t SpecialF) String() string

type String

type String string

func (String) Add added in v0.1.4

func (s String) Add(n Node) (Node, error)

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) Eval added in v0.1.4

func (s String) Eval(context.Context, *World) (Node, error)

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(n Node) (bool, error)

func (String) PrintTo added in v0.1.4

func (s String) PrintTo(w io.Writer, m PrintMode) (int, 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(n Node) error

func (*StringBuilder) Equals added in v0.1.4

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

func (*StringBuilder) Eval added in v0.1.4

func (t *StringBuilder) Eval(context.Context, *World) (Node, error)

func (StringBuilder) GoString added in v0.1.4

func (S StringBuilder) GoString() string

func (*StringBuilder) PrintTo added in v0.1.4

func (t *StringBuilder) PrintTo(w io.Writer, m PrintMode) (int, error)

func (*StringBuilder) Sequence added in v0.1.4

func (S *StringBuilder) Sequence() Node

type Symbol

type Symbol int

func NewSymbol

func NewSymbol(s string) Symbol

func (Symbol) Equals

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

func (Symbol) Eval

func (s Symbol) Eval(_ context.Context, w *World) (Node, error)

func (Symbol) GoString added in v0.1.4

func (s Symbol) GoString() string

func (Symbol) PrintTo

func (s Symbol) PrintTo(w io.Writer, m PrintMode) (int, error)

func (Symbol) String

func (s Symbol) String() string

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) error) error

func (Variables) Set

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

type VectorBuilder

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

func (*VectorBuilder) Add

func (v *VectorBuilder) Add(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) DefineVariable

func (w *World) DefineVariable(name Symbol, getter func() Node)

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) Get

func (w *World) Get(name Symbol) (Node, 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) error) error

func (*World) Set

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

func (*World) SetErrout

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

func (*World) SetOrDefineParameter

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

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() *_ReaderNode

func (*World) Stdout

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

Directories

Path Synopsis
cmd
examples
pkg

Jump to

Keyboard shortcuts

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