internal

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2020 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package sabre provides data structures, reader for reading LISP source into data structures and functions for evluating forms against a context.

Index

Constants

View Source
const (
	IndentLevel = 4
)
View Source
const MAX_STACK_CALL = 20

maximum stack to be stored

Variables

View Source
var (
	// ErrSkip can be returned by reader macro to indicate a no-op form which
	// should be discarded (e.g., Comments).
	ErrSkip = errors.New("skip expr")

	// ErrEOF is returned when stream ends prematurely to indicate that more
	// data is needed to complete the current form.
	ErrEOF = errors.New("unexpected EOF")
)
View Source
var (
	// Def implements (def symbol value) form for defining bindings.
	Def = SpecialForm{
		Name:  "def",
		Parse: parseDef,
	}

	// Lambda defines an anonymous function and returns. Must have the form
	// (fn* name? [arg*] expr*) or (fn* name? ([arg]* expr*)+)
	Lambda = SpecialForm{
		Name:  "fn*",
		Parse: fnParser(false),
	}

	// Macro defines an anonymous function and returns. Must have the form
	// (macro* name? [arg*] expr*) or (fn* name? ([arg]* expr*)+)
	Macro = SpecialForm{
		Name:  "macro*",
		Parse: fnParser(true),
	}

	// Let implements the (let [binding*] expr*) form. expr are evaluated
	// with given local bindings.
	Let = SpecialForm{
		Name:  "let",
		Parse: parseLet,
	}

	// Do special form evaluates args one by one and returns the result of
	// the last expr.
	Do = SpecialForm{
		Name:  "do",
		Parse: parseDo,
	}

	// If implements if-conditional flow using (if test then else?) form.
	If = SpecialForm{
		Name:  "if",
		Parse: parseIf,
	}

	// SimpleQuote prevents a form from being evaluated.
	SimpleQuote = SpecialForm{
		Name:  "quote",
		Parse: parseSimpleQuote,
	}

	// SyntaxQuote recursively applies the quoting to the form.
	SyntaxQuote = SpecialForm{
		Name:  "syntax-quote",
		Parse: parseSyntaxQuote,
	}
)
View Source
var ErrResolving = errors.New("unable to resolve symbol")

ErrResolving is returned when a scope implementation fails to resolve a binding for given symbol.

Functions

func ClearStack added in v0.9.0

func ClearStack(scope Scope)

func Compare

func Compare(v1, v2 Value) bool

Compare compares two values in an identity independent manner. If v1 has `Compare(Value) bool` method, the comparison is delegated to it as `v1.Compare(v2)`.

func RemovePrefix added in v0.9.0

func RemovePrefix(str string) string

Types

type Any

type Any struct{ V reflect.Value }

Any can be used to wrap arbitrary Go value into spirit scope.

func (Any) Eval

func (any Any) Eval(_ Scope) (Value, error)

Eval returns itself.

func (Any) String

func (any Any) String() string

type ArgumentError added in v0.9.0

type ArgumentError struct {
	Fn  string
	Got int
}

func (ArgumentError) Error added in v0.9.0

func (a ArgumentError) Error() string

type Assoc added in v0.8.1

type Assoc interface {
	Value

	// Set should set the value and returns new structure with updated value
	Set(Value, Value) Value

	// Get should get a value mapped under passed argument
	Get(Value) Value
}

Assoc represents value that can be mapped

type Atom added in v0.8.1

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

Atom is a thread-safe reference type

func NewAtom added in v0.8.1

func NewAtom(val Value) *Atom

func (*Atom) Eval added in v0.8.1

func (a *Atom) Eval(_ Scope) (Value, error)

func (*Atom) GetVal added in v0.8.1

func (a *Atom) GetVal() Value

func (*Atom) String added in v0.8.1

func (a *Atom) String() string

func (*Atom) UpdateState added in v0.8.1

func (a *Atom) UpdateState(scope Scope, fn Invokable) (Value, error)

type Bool

type Bool bool

Bool represents a boolean value.

func (Bool) Eval

func (b Bool) Eval(_ Scope) (Value, error)

Eval returns the underlying value.

func (Bool) String

func (b Bool) String() string

type Call added in v0.8.1

type Call struct {
	Position
	Name string
}

type Character

type Character rune

Character represents a character literal. For example, \a, \b, \1, \∂ etc are valid character literals. In addition, special literals like \newline, \space etc are supported by the reader.

func (Character) Eval

func (char Character) Eval(_ Scope) (Value, error)

Eval simply returns itself since Chracters evaluate to themselves.

func (Character) String

func (char Character) String() string

type Class added in v0.8.1

type Class struct {
	Name          string
	Parent        *Class
	Members       *HashMap
	Methods       *HashMap
	StaticsMethod *HashMap
}

func (Class) Eval added in v0.8.1

func (c Class) Eval(_ Scope) (Value, error)

func (Class) Exists added in v0.8.1

func (c Class) Exists(name Keyword) bool

finds whether member or method exists

func (Class) GetMember added in v0.8.1

func (c Class) GetMember(name Keyword) (Value, bool)

func (Class) GetMembers added in v0.8.1

func (c Class) GetMembers() map[string]Value

func (Class) GetMethod added in v0.8.1

func (c Class) GetMethod(name Keyword) (Invokable, bool)

func (Class) GetMethods added in v0.8.1

func (c Class) GetMethods() map[string]Invokable

func (Class) GetStaticMethod added in v0.9.0

func (c Class) GetStaticMethod(name Keyword) (Invokable, bool)

func (*Class) Inherit added in v0.9.0

func (c *Class) Inherit(parent *Class)

func (Class) Invoke added in v0.8.1

func (c Class) Invoke(scope Scope, args ...Value) (Value, error)

func (Class) PrettyPrint added in v0.8.1

func (c Class) PrettyPrint(indent int) string

func (Class) String added in v0.8.1

func (c Class) String() string

type Comparable added in v0.8.1

type Comparable interface {
	Value
	Compare(other Value) bool
}

Comparable can be implemented by Value types to support comparison. See Compare().

type EvalError

type EvalError struct {
	Position
	Cause      error
	StackTrace string
	Form       Value
}

EvalError represents error during evaluation.

func (EvalError) Error

func (ee EvalError) Error() string

func (EvalError) Unwrap

func (ee EvalError) Unwrap() error

Unwrap returns the underlying cause of this error.

type Fn

type Fn struct {
	Args     []string
	Variadic bool
	Body     Value
	Scope    Scope
	Func     func(scope Scope, args []Value) (Value, error)
}

Fn represents a function or macro definition.

func (*Fn) Compare

func (fn *Fn) Compare(v Value) bool

Compare returns true if 'other' is also a function and has the same signature and body.

func (*Fn) Eval

func (fn *Fn) Eval(_ Scope) (Value, error)

Eval returns the function itself.

func (*Fn) Invoke

func (fn *Fn) Invoke(scope Scope, args ...Value) (Value, error)

Invoke executes the function with given arguments.

func (Fn) String

func (fn Fn) String() string

type Future added in v0.8.1

type Future struct {
	Realized bool
	Value    Value
	Channel  chan Value
}

func (*Future) Eval added in v0.8.1

func (c *Future) Eval(_ Scope) (Value, error)

func (Future) String added in v0.8.1

func (c Future) String() string

func (*Future) Submit added in v0.8.1

func (c *Future) Submit(scope Scope, form Value)

type HashMap

type HashMap struct {
	Position
	Data hashmap.Map
}

HashMap is persistant and does not mutate on change under the hood, it uses structural sharing to reduce the cost of copying

func NewHashMap added in v0.9.0

func NewHashMap() *HashMap

func (*HashMap) Compare added in v0.9.0

func (hm *HashMap) Compare(other Value) bool

Compare implements Comparable. It compares each key and value recursively, note that order is not important when comparing

func (*HashMap) Conj added in v0.9.0

func (hm *HashMap) Conj(vals ...Value) Seq

func (*HashMap) Cons added in v0.9.0

func (hm *HashMap) Cons(v Value) Seq

func (*HashMap) Delete added in v0.9.0

func (hm *HashMap) Delete(k Value) *HashMap

func (*HashMap) Eval

func (hm *HashMap) Eval(scope Scope) (Value, error)

func (*HashMap) First added in v0.9.0

func (hm *HashMap) First() Value

func (*HashMap) Get

func (hm *HashMap) Get(key Value) Value

func (*HashMap) Invoke added in v0.9.0

func (hm *HashMap) Invoke(scope Scope, args ...Value) (Value, error)

func (*HashMap) Next added in v0.9.0

func (hm *HashMap) Next() Seq

func (HashMap) PrettyPrint added in v0.9.0

func (hm HashMap) PrettyPrint(indent int) string

func (*HashMap) Set

func (hm *HashMap) Set(k, v Value) Value

func (*HashMap) Size added in v0.9.0

func (hm *HashMap) Size() int

HashMap implements Seq interface. Note that the order of items is unstable

func (HashMap) String

func (hm HashMap) String() string

type ImplementError added in v0.9.0

type ImplementError struct {
	Name string
	Val  Value
}

func (ImplementError) Error added in v0.9.0

func (i ImplementError) Error() string

type ImportError added in v0.9.0

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

func (ImportError) Error added in v0.9.0

func (i ImportError) Error() string

type Invokable

type Invokable interface {
	Value
	Invoke(scope Scope, args ...Value) (Value, error)
}

Invokable represents any value that supports invocation. Vector, Fn etc support invocation.

type Keyword

type Keyword string

Keyword represents a keyword literal.

func (Keyword) Eval

func (kw Keyword) Eval(_ Scope) (Value, error)

Eval simply returns itself since Keywords evaluate to themselves.

func (Keyword) Invoke

func (kw Keyword) Invoke(scope Scope, args ...Value) (Value, error)

Invoke enables keyword lookup for maps.

func (Keyword) String

func (kw Keyword) String() string

type LazySeq added in v0.8.1

type LazySeq struct {
	Min  int
	Max  int
	Step int
}

Implements Seq interface but lazy

func (LazySeq) Conj added in v0.8.1

func (l LazySeq) Conj(v ...Value) Seq

func (LazySeq) Cons added in v0.8.1

func (l LazySeq) Cons(v Value) Seq

func (LazySeq) Eval added in v0.8.1

func (l LazySeq) Eval(_ Scope) (Value, error)

func (LazySeq) First added in v0.8.1

func (l LazySeq) First() Value

func (LazySeq) Next added in v0.8.1

func (l LazySeq) Next() Seq

func (LazySeq) Size added in v0.8.1

func (l LazySeq) Size() int

func (LazySeq) String added in v0.8.1

func (l LazySeq) String() string

type List

type List struct {
	Values
	Position
	// contains filtered or unexported fields
}

List represents an list of forms/vals. Evaluating a list leads to a function invocation.

func (*List) Eval

func (lf *List) Eval(scope Scope) (Value, error)

Eval performs an invocation.

func (List) String

func (lf List) String() string

type MapScope

type MapScope struct {
	Stack
	// contains filtered or unexported fields
}

MapScope implements Scope using a Go native hash-map.

func New

func New() *MapScope

New initializes a new scope with all the core bindings.

func NewScope

func NewScope(parent Scope) *MapScope

NewScope returns an instance of MapScope with no bindings. If you need builtin special forms, pass result of New() as argument.

func (*MapScope) Bind

func (scope *MapScope) Bind(symbol string, v Value) error

Bind adds the given value to the scope and binds the symbol to it.

func (*MapScope) BindGo

func (scope *MapScope) BindGo(symbol string, v interface{}) error

BindGo is similar to Bind but handles conversion of Go value 'v' to

Value type. See `ValueOf()`

func (*MapScope) Parent

func (scope *MapScope) Parent() Scope

Parent returns the parent scope of this scope.

func (*MapScope) Resolve

func (scope *MapScope) Resolve(symbol string) (Value, error)

Resolve finds the value bound to the given symbol and returns it if found in this scope or parent scope if any. Returns error otherwise.

type Module

type Module []Value

Module represents a group of forms. Evaluating a module leads to evaluation of each form in order and result will be the result of last evaluation.

func (Module) Compare

func (mod Module) Compare(v Value) bool

Compare returns true if the 'v' is also a module and all forms in the module are equivalent.

func (Module) Eval

func (mod Module) Eval(scope Scope) (Value, error)

Eval evaluates all the vals in the module body and returns the result of the last evaluation.

func (Module) String

func (mod Module) String() string

type MultiFn

type MultiFn struct {
	Name    string
	IsMacro bool
	Methods []Fn
}

MultiFn represents a multi-arity function or macro definition.

func (MultiFn) Compare

func (multiFn MultiFn) Compare(v Value) bool

Compare returns true if 'v' is also a MultiFn and all methods are equivalent.

func (MultiFn) Eval

func (multiFn MultiFn) Eval(_ Scope) (Value, error)

Eval returns the multiFn definition itself.

func (MultiFn) Expand

func (multiFn MultiFn) Expand(scope Scope, args []Value) (Value, error)

Expand executes the macro body and returns the result of the expansion.

func (MultiFn) Invoke

func (multiFn MultiFn) Invoke(scope Scope, args ...Value) (Value, error)

Invoke dispatches the call to a method based on number of arguments.

func (MultiFn) String

func (multiFn MultiFn) String() string

type Nil

type Nil struct{}

Nil represents a nil value.

func (Nil) Eval

func (n Nil) Eval(_ Scope) (Value, error)

Eval returns the underlying value.

func (Nil) String

func (n Nil) String() string

type Number added in v0.8.1

type Number float64

Number represents double precision floating point numbers

func (Number) Eval added in v0.8.1

func (n Number) Eval(_ Scope) (Value, error)

Eval simply returns itself since Floats evaluate to themselves.

func (Number) String added in v0.8.1

func (n Number) String() string

type OSError added in v0.9.0

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

func (OSError) Error added in v0.9.0

func (o OSError) Error() string

type Object added in v0.8.1

type Object struct {
	InstanceOf Class
	Members    *HashMap
}

func (Object) Eval added in v0.8.1

func (o Object) Eval(_ Scope) (Value, error)

func (Object) Get added in v0.8.2

func (o Object) Get(key Value) Value

func (Object) GetMember added in v0.8.1

func (o Object) GetMember(name Keyword) (Value, bool)

func (Object) GetMethod added in v0.8.1

func (o Object) GetMethod(name Keyword) (Invokable, bool)

func (Object) PrettyPrint added in v0.8.1

func (o Object) PrettyPrint(indent int) string

func (Object) Set added in v0.8.1

func (o Object) Set(key, value Value) Value

func (Object) String added in v0.8.1

func (o Object) String() string

type Position

type Position struct {
	File   string
	Line   int
	Column int
}

Position represents the positional information about a value read by reader.

func (Position) GetPos

func (pi Position) GetPos() (file string, line, col int)

GetPos returns the file, line and column values.

func (*Position) SetPos

func (pi *Position) SetPos(file string, line, col int)

SetPos sets the position information.

func (Position) String

func (pi Position) String() string

type PrettyPrinter added in v0.9.0

type PrettyPrinter interface {
	PrettyPrint(indent int) string
}

type ReadError

type ReadError struct {
	Position
	Cause  error
	Messag string
}

ReadError wraps the parsing/eval errors with relevant information.

func (ReadError) Error

func (err ReadError) Error() string

func (ReadError) Unwrap

func (err ReadError) Unwrap() error

Unwrap returns underlying cause of the error.

type Reader

type Reader struct {
	File string
	// contains filtered or unexported fields
}

Reader provides functions to parse characters from a stream into symbolic expressions or forms.

func NewReader

func NewReader(rs io.Reader) *Reader

NewReader returns a lisp reader instance which can read forms from rs. Reader behavior can be customized by using SetMacro to override or remove from the default read table. File name will be inferred from the reader value and type information or can be set manually on the Reader.

func (*Reader) All

func (rd *Reader) All() (Value, error)

All consumes characters from stream until EOF and returns a list of all the forms parsed. Any no-op forms (e.g., comment) returned will not be included in the result.

func (*Reader) IsTerminal

func (rd *Reader) IsTerminal(r rune) bool

IsTerminal returns true if the rune should terminate a form. ReaderMacro trigger runes defined in the read table and all space characters including "," are considered terminal.

func (*Reader) NextRune

func (rd *Reader) NextRune() (rune, error)

NextRune returns next rune from the stream and advances the stream.

func (*Reader) One

func (rd *Reader) One() (Value, error)

One consumes characters from underlying stream until a complete form is parsed and returns the form while ignoring the no-op forms like comments. Except EOF, all errors will be wrapped with ReaderError type along with the positional information obtained using Position().

func (Reader) Position

func (rd Reader) Position() Position

Position returns information about the stream including file name and the position of the reader.

func (*Reader) SetMacro

func (rd *Reader) SetMacro(init rune, macro ReaderMacro, isDispatch bool)

SetMacro sets the given reader macro as the handler for init rune in the read table. Overwrites if a macro is already present. If the macro value given is nil, entry for the init rune will be removed from the read table. isDispatch decides if the macro is a dispatch macro and takes effect only after a '#' sign.

func (*Reader) SkipSpaces

func (rd *Reader) SkipSpaces() error

SkipSpaces consumes and discards runes from stream repeatedly until a character that is not a whitespace is identified. Along with standard unicode white-space characters "," is also considered a white-space and discarded.

func (*Reader) Unread

func (rd *Reader) Unread(runes ...rune)

Unread can be used to return runes consumed from the stream back to the stream. Un-reading more runes than read is guaranteed to work but might cause inconsistency in stream positional information.

type ReaderMacro

type ReaderMacro func(rd *Reader, init rune) (Value, error)

ReaderMacro implementations can be plugged into the Reader to extend, override or customize behavior of the reader.

type ResolveError added in v0.9.0

type ResolveError struct {
	Sym Symbol
}

func (ResolveError) Error added in v0.9.0

func (r ResolveError) Error() string

type Scope

type Scope interface {
	Push(Call)
	Pop() Call
	StackTrace() string
	Parent() Scope
	Bind(symbol string, v Value) error
	Resolve(symbol string) (Value, error)
}

Scope implementation is responsible for managing value bindings.

type Seq

type Seq interface {
	Value
	// First should return first value of the sequence or nil if the
	// sequence is empty.
	First() Value
	// Next should return the remaining sequence when the first value
	// is excluded.
	Next() Seq
	// Cons should add the value to the beginning of the sequence and
	// return the new sequence.
	Cons(v Value) Seq
	// Conj should join the given values to the sequence and return a
	// new sequence.
	Conj(vals ...Value) Seq

	Size() int
}

Seq implementations represent a sequence/list of values.

type Set

type Set struct {
	Values
	Position
}

Set represents a list of unique values. (Experimental)

func (Set) Eval

func (set Set) Eval(scope Scope) (Value, error)

Eval evaluates each value in the set form and returns the resultant values as new set.

func (Set) String

func (set Set) String() string

type SpecialForm

type SpecialForm struct {
	Name  string
	Parse func(scope Scope, args []Value) (*Fn, error)
}

SpecialForm is a Value type for representing special forms that will be subjected to an intermediate Parsing stage before evaluation.

func (SpecialForm) Eval

func (sf SpecialForm) Eval(_ Scope) (Value, error)

Eval always returns error since it is not allowed to directly evaluate a special form.

func (SpecialForm) String

func (sf SpecialForm) String() string

type Spirit added in v0.9.0

type Spirit struct {
	Stack

	Bindings map[nsSymbol]Value
	Files    []string
	// contains filtered or unexported fields
}

Spirit instance

func NewSpirit added in v0.9.0

func NewSpirit() *Spirit

returns new Spirit instance

func (*Spirit) AddFile added in v0.9.0

func (s *Spirit) AddFile(file string)

AddFile adds file to slice of imported files to prevent circular dependency.

func (*Spirit) Bind added in v0.9.0

func (spirit *Spirit) Bind(symbol string, v Value) error

Bind binds the given name to the given Value into the spirit interpreter context.

func (*Spirit) BindGo added in v0.9.0

func (spirit *Spirit) BindGo(symbol string, v interface{}) error

BindGo is similar to Bind but handles conversion of Go value 'v' to internal Value type.

func (*Spirit) CurrentNS added in v0.9.0

func (spirit *Spirit) CurrentNS() string

CurrentNS returns the current active namespace.

func (*Spirit) Eval added in v0.9.0

func (spirit *Spirit) Eval(v Value) (Value, error)

Eval evaluates the given value in spirit context.

func (*Spirit) FileImported added in v0.9.0

func (s *Spirit) FileImported(file string) bool

func (*Spirit) Parent added in v0.9.0

func (spirit *Spirit) Parent() Scope

Parent always returns nil to represent this is the root scope.

func (*Spirit) ReadEval added in v0.9.0

func (spirit *Spirit) ReadEval(r io.Reader) (Value, error)

ReadEval reads from the given reader and evaluates all the forms obtained in spirit context.

func (*Spirit) ReadEvalStr added in v0.9.0

func (spirit *Spirit) ReadEvalStr(src string) (Value, error)

ReadEvalStr reads the source and evaluates it in spirit context.

func (*Spirit) ReadFile added in v0.9.0

func (spirit *Spirit) ReadFile(filePath string) (Value, error)

ReadFile reads the content of the filename given. Use this to prevent recursive source

func (*Spirit) Resolve added in v0.9.0

func (spirit *Spirit) Resolve(symbol string) (Value, error)

Resolve finds the value bound to the given symbol and returns it if found in the spirit context and returns it.

func (*Spirit) SwitchNS added in v0.9.0

func (spirit *Spirit) SwitchNS(sym Symbol) error

SwitchNS changes the current namespace to the string value of given symbol.

type Stack added in v0.8.1

type Stack []Call

Stack contains function call. When fn is called, Call will be pushed in Stack, when the fn exits, the stack is popped

func (*Stack) Pop added in v0.8.1

func (s *Stack) Pop() Call

Pops removes function call from Stack

func (*Stack) Push added in v0.8.1

func (s *Stack) Push(call Call)

Add function call to stack

func (Stack) Size added in v0.8.1

func (s Stack) Size() int

func (*Stack) StackTrace added in v0.8.1

func (s *Stack) StackTrace() string

StackTrace returns string representing current stack trace

type String

type String string

String represents double-quoted string literals. String Form represents the true string value obtained from the reader. Escape sequences are not applicable at this level.

func (String) Conj

func (se String) Conj(vals ...Value) Seq

Conj joins the given values to list of characters of the string and returns the new sequence.

func (String) Cons

func (se String) Cons(v Value) Seq

Cons converts the string to character sequence and adds the given value to the beginning of the list.

func (String) Eval

func (se String) Eval(_ Scope) (Value, error)

Eval simply returns itself since Strings evaluate to themselves.

func (String) First

func (se String) First() Value

First returns the first character if string is not empty, nil otherwise.

func (String) Next

func (se String) Next() Seq

Next slices the string by excluding first character and returns the remainder.

func (String) Size added in v0.8.1

func (se String) Size() int

func (String) String

func (se String) String() string

type Symbol

type Symbol struct {
	Position
	Value string
}

Symbol represents a name given to a value in memory.

func (Symbol) Compare

func (sym Symbol) Compare(v Value) bool

Compare compares this symbol to the given value. Returns true if the given value is a symbol with same data.

func (Symbol) Eval

func (sym Symbol) Eval(scope Scope) (Value, error)

Eval returns the value bound to this symbol in current context. If the symbol is in fully qualified form (i.e., separated by '.'), eval does recursive member access.

func (Symbol) String

func (sym Symbol) String() string

type Type

type Type struct{ T reflect.Type }

Type represents the type value of a given value. Type also implements Value type.

func TypeOf added in v0.8.1

func TypeOf(value interface{}) Type

func (Type) Eval

func (t Type) Eval(_ Scope) (Value, error)

Eval returns the type value itself.

func (Type) Invoke

func (t Type) Invoke(scope Scope, args ...Value) (Value, error)

Invoke creates zero value of the given type.

func (Type) String

func (t Type) String() string

type TypeError added in v0.9.0

type TypeError struct {
	Expected Value
	Got      Value
}

func (TypeError) Error added in v0.9.0

func (t TypeError) Error() string

type Value

type Value interface {
	// String should return the LISP representation of the value.
	String() string
	// Eval should evaluate this value against the scope and return
	// the resultant value or an evaluation error.
	Eval(scope Scope) (Value, error)
}

Value represents data/forms in spirit. This includes those emitted by Reader, values obtained as result of an evaluation etc.

func Eval

func Eval(scope Scope, form Value) (Value, error)

Eval evaluates the given form against the scope and returns the result of evaluation.

func EvalValueLast added in v0.8.1

func EvalValueLast(scope Scope, vals []Value) (Value, error)

evaluates list and only returns the last expression

func EvalValueList added in v0.8.1

func EvalValueList(scope Scope, vals []Value) ([]Value, error)

evaluates list and returns the evaluated list

func MacroExpand

func MacroExpand(scope Scope, form Value) (Value, bool, error)

MacroExpand expands the macro invocation form.

func ReadEval

func ReadEval(scope Scope, r io.Reader) (Value, error)

ReadEval consumes data from reader 'r' till EOF, parses into forms and evaluates all the forms obtained and returns the result.

func ReadEvalStr

func ReadEvalStr(scope Scope, src string) (Value, error)

ReadEvalStr is a convenience wrapper for Eval that reads forms from string and evaluates for result.

func ValueOf

func ValueOf(v interface{}) Value

ValueOf converts a Go value to spirit Value type. If 'v' is already a Value type, it is returned as is. Primitive Go values like string, rune, int, float, bool are converted to the right spirit Value types. Functions are converted to the wrapper 'Fn' type. Value of type 'reflect.Type' will be wrapped as 'Type' which enables initializing a value of that type when invoked. All other types will be wrapped using 'Any' type.

type Values

type Values []Value

Values represents a list of values and implements the Seq interface.

func (Values) Compare

func (vals Values) Compare(v Value) bool

Compare compares the values in this sequence to the other sequence. other sequence will be realized for comparison.

func (Values) Conj

func (vals Values) Conj(args ...Value) Seq

Conj returns a new sequence where 'v' is appended to the values.

func (Values) Cons

func (vals Values) Cons(v Value) Seq

Cons returns a new sequence where 'v' is prepended to the values.

func (Values) Eval

func (vals Values) Eval(_ Scope) (Value, error)

Eval returns itself.

func (Values) First

func (vals Values) First() Value

First returns the first value in the list if the list is not empty. Returns Nil{} otherwise.

func (Values) Next

func (vals Values) Next() Seq

Next returns a new sequence containing values after the first one. If there are no values to create a next sequence, returns nil.

func (Values) Size

func (vals Values) Size() int

Size returns the number of items in the list.

func (Values) String

func (vals Values) String() string

func (Values) Uniq

func (vals Values) Uniq() []Value

Uniq removes all the duplicates from the given value array. TODO: remove this naive implementation

type Vector

type Vector struct {
	Position
	Vec vector.Vector
}

func NewVector added in v0.9.0

func NewVector() *Vector

func (*Vector) Compare added in v0.9.0

func (p *Vector) Compare(other Value) bool

Compare implements Comparable which recursively compare values between other value. Order is important

func (*Vector) Conj added in v0.8.1

func (p *Vector) Conj(vals ...Value) Seq

func (*Vector) Cons added in v0.9.0

func (p *Vector) Cons(v Value) Seq

func (*Vector) Eval

func (p *Vector) Eval(scope Scope) (Value, error)

func (*Vector) First added in v0.9.0

func (p *Vector) First() Value

func (*Vector) Get added in v0.9.0

func (p *Vector) Get(i Value) Value

func (*Vector) GetValues added in v0.9.0

func (p *Vector) GetValues() []Value

func (*Vector) Index added in v0.9.0

func (p *Vector) Index(i int) Value

func (*Vector) Invoke

func (p *Vector) Invoke(scope Scope, args ...Value) (Value, error)

func (*Vector) Next added in v0.9.0

func (p *Vector) Next() Seq

func (*Vector) PrettyPrint added in v0.9.0

func (p *Vector) PrettyPrint(indent int) string

func (*Vector) Set added in v0.9.0

func (p *Vector) Set(i Value, v Value) Value

func (*Vector) SetPosition added in v0.9.0

func (p *Vector) SetPosition(pos Position) *Vector

func (*Vector) Size added in v0.9.0

func (p *Vector) Size() int

func (*Vector) String

func (p *Vector) String() string

func (*Vector) SubVector added in v0.9.0

func (p *Vector) SubVector(i, j int) Seq

Directories

Path Synopsis
Package repl provides a REPL implementation and options to expose internal features through a read-eval-print-loop.
Package repl provides a REPL implementation and options to expose internal features through a read-eval-print-loop.

Jump to

Keyboard shortcuts

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