spirit

package module
v0.8.0 Latest Latest
Warning

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

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

README

Spirit

Spirit is a scripting, functional language inspired by Clojure. Spirit does not target JVM machines instead it's interpreted line by line. This has the advantage of fast startup and suitable for scripting environment.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindAll

func BindAll(scope internal.Scope) error

BindAll binds all core functions into the given scope.

func Case

func Case(scope internal.Scope, args []internal.Value) (internal.Value, error)

Case implements the switch case construct.

func Gt

func Gt(base float64, args ...float64) bool

Gt returns true if the given args are monotonically decreasing.

func GtE

func GtE(base float64, args ...float64) bool

GtE returns true if the given args are monotonically decreasing or all equal.

func Implements

func Implements(v interface{}, t internal.Type) (bool, error)

Implements checks if given value implements the interface represented by 't'. Returns error if 't' does not represent an interface type.

func Lt

func Lt(base float64, args ...float64) bool

Lt returns true if the given args are monotonically increasing.

func LtE

func LtE(base float64, args ...float64) bool

LtE returns true if the given args are monotonically increasing or are all equal.

func MacroExpand

func MacroExpand(scope internal.Scope, f internal.Value) (internal.Value, error)

MacroExpand is a wrapper around the internal MacroExpand function that ignores the expanded bool flag.

func MakeString

func MakeString(vals ...internal.Value) internal.Value

MakeString returns stringified version of all args.

func Printf

func Printf(format string, args ...interface{}) error

Printf is an alias for fmt.Printf which ignores the return values.

func Println

func Println(args ...interface{}) error

Println is an alias for fmt.Println which ignores the return values.

func Random

func Random(max int) int

func Read

func Read(prompt string) (string, error)

Reads from stdin and returns string

func ReadFile

func ReadFile(name string) (string, error)

func Realize

func Realize(seq internal.Seq) *internal.List

Realize realizes a sequence by continuously calling First() and Next() until the sequence becomes nil.

func Shell

func Shell(command string) (*internal.HashMap, error)

func Shuffle

func Shuffle(seq internal.Seq) internal.Seq

func ThreadFirst

func ThreadFirst(scope internal.Scope, args []internal.Value) (internal.Value, error)

ThreadFirst threads the expressions through forms by inserting result of eval as first argument to next expr.

func ThreadLast

func ThreadLast(scope internal.Scope, args []internal.Value) (internal.Value, error)

ThreadLast threads the expressions through forms by inserting result of eval as last argument to next expr.

func Throw

func Throw(scope internal.Scope, args ...internal.Value) error

Throw converts args to strings and returns an error with all the strings joined.

func ToType

func ToType(to internal.Type, val internal.Value) (internal.Value, error)

ToType attempts to convert given internal value to target type. Returns error if conversion not possible.

func TypeOf

func TypeOf(v interface{}) internal.Value

TypeOf returns the type information object for the given argument.

Types

type Any

type Any interface{}

func Add

func Add(args ...Any) Any

Add adds given floating point numbers and returns the sum.

func Divide

func Divide(first Any, args ...Any) Any

Divide returns the product of given numbers.

func Multiply

func Multiply(first Any, args ...Any) Any

Multiply multiplies the given args to 1 and returns the result.

func Sub

func Sub(x Any, args ...Any) Any

Sub subtracts args from 'x' and returns the final result.

type Atom

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

func (*Atom) Eval

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

func (*Atom) GetVal

func (a *Atom) GetVal() internal.Value

func (*Atom) String

func (a *Atom) String() string

func (*Atom) UpdateState

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

type Spirit

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

Spirit instance

func New

func New() *Spirit

returns new Spirit instance

func (*Spirit) Bind

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

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

func (*Spirit) BindGo

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

func (spirit *Spirit) CurrentNS() string

CurrentNS returns the current active namespace.

func (*Spirit) Eval

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

Eval evaluates the given value in spirit context.

func (*Spirit) Parent

func (spirit *Spirit) Parent() internal.Scope

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

func (*Spirit) ReadEval

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

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

func (*Spirit) ReadEvalStr

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

ReadEvalStr reads the source and evaluates it in spirit context.

func (*Spirit) Resolve

func (spirit *Spirit) Resolve(symbol string) (internal.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

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

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

Directories

Path Synopsis
cmd
Package sabre provides data structures, reader for reading LISP source into data structures and functions for evluating forms against a context.
Package sabre provides data structures, reader for reading LISP source into data structures and functions for evluating forms against a context.
repl
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