Documentation ¶
Overview ¶
Z3S5 Lisp by Erich Rast. A Lisp-1 for Go based on Nukata Lisp 2.0 by SUZUKI Hisao. MIT License, see the accompanying LICENSE file.
Z3S5 Lisp by Erich Rast. A Lisp-1 for Go based on Nukata Lisp 2.0 by SUZUKI Hisao. MIT License, see the accompanying LICENSE file.
Index ¶
- Constants
- Variables
- func AsLispBool(b bool) any
- func Btoi(b []byte) uint64
- func ConvertIntsToNumbers(a []any)
- func ConvertNumbersToInts(a []any)
- func CopyMap(m map[any]any) map[any]any
- func DictToArray(dict any) []any
- func GetGID() uint64
- func Itob(v uint64) []byte
- func ListToArray(li *Cell) []any
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func NewClosure(carity int, args *Cell, body *Cell, env *Cell) any
- func NewLambda(carity int, args *Cell, body *Cell, env *Cell) any
- func NewMacro(carity int, args *Cell, body *Cell, env *Cell) any
- func QqExpand(x any) any
- func QqQuote(x any) any
- func ReverseArray(arr []any) []any
- func ReverseStr(s string) string
- func Same(a, b any) bool
- func SleepHiRes(duration time.Duration, cancel *int32)
- func Str(x any) string
- func Str2(x any, quoteString bool) string
- func ToBool(a any) bool
- func ToFloat64(x any) float64
- func ToInt64(caller string, a any) int64
- func ToMaybeUInt64(a any) (uint64, bool)
- func ToUInt16(a any) uint16
- func ToUInt32(a any) uint32
- func ToUInt8(a any) uint8
- type Arg
- type Audio
- type BasicAudio
- type BasicEditor
- func (ed *BasicEditor) Color(bg bool) Color
- func (ed *BasicEditor) EndInput() (string, bool)
- func (ed *BasicEditor) EndInputCallback() func()
- func (ed *BasicEditor) Print(s string) (int, int)
- func (ed *BasicEditor) ResetColor()
- func (ed *BasicEditor) SetColor(bg bool, color Color)
- func (ed *BasicEditor) StartInput(cb func())
- type BasicRuntime
- type Boxed
- type BoxedArray
- type BufferedReader
- type BuiltInFunc
- type Cell
- type Closure
- type Color
- type Dict
- type Editing
- type EvalError
- type Externalizable
- type Func
- type Future
- type Interp
- func (interp *Interp) Boot() error
- func (interp *Interp) Break()
- func (interp *Interp) CanExternalize(a any) bool
- func (interp *Interp) Def(name string, carity int, body func([]any) any)
- func (interp *Interp) DefBoxed(sort *Sym)
- func (interp *Interp) DefaultPrintError(err any)
- func (interp *Interp) Define_Base()
- func (interp *Interp) Define_Console()
- func (interp *Interp) Define_DB()
- func (interp *Interp) Define_Decimal()
- func (interp *Interp) Define_FileIO()
- func (interp *Interp) Define_Float()
- func (interp *Interp) Define_Ling()
- func (interp *Interp) Define_StyledText()
- func (interp *Interp) EndLineInput()
- func (interp *Interp) Eval(expression any, env *Cell) any
- func (interp *Interp) EvalFile(path string) bool
- func (interp *Interp) EvalString(s string) (any, error)
- func (interp *Interp) ExpandMacros(x any, count int) any
- func (interp *Interp) ExpectInts(caller string, a []any, offset, n int) []int
- func (interp *Interp) Externalize(env *Cell, a any) string
- func (interp *Interp) GetGlobalVar(sym *Sym) (any, bool)
- func (interp *Interp) HandleError(err any) (any, bool)
- func (interp *Interp) InputCond() *sync.Cond
- func (interp *Interp) InputLock() *sync.Mutex
- func (interp *Interp) Lock()
- func (interp *Interp) MaybeLoadUserInit() error
- func (interp *Interp) MustParseBlobArgs(caller string, a []any) ([]byte, int, int)
- func (interp *Interp) Print(s string)
- func (interp *Interp) PrintError(err any)
- func (interp *Interp) RLock()
- func (interp *Interp) RUnlock()
- func (interp *Interp) Run(input io.Reader, source *Source) bool
- func (interp *Interp) Runtime() any
- func (interp *Interp) SafeEval(expression any, env *Cell) (result any, err any)
- func (interp *Interp) SetGlobalVar(sym *Sym, val any)
- func (interp *Interp) SetInteractive(on bool)
- func (interp *Interp) StartREPL()
- func (interp *Interp) Streams() *sync.Map
- func (interp *Interp) UnbindGlobalVar(sym *Sym)
- func (interp *Interp) Unlock()
- type Lambda
- type Macro
- type Permissions
- type Reader
- type Runtime
- type Seeker
- type Source
- type Stream
- type Sym
- type ValueHolder
- type Writer
- type WriterAt
Constants ¶
const ( SourceSortFile = iota SourceSortInternal )
const DEFAULT_BUFFMAX = 1048576 // default max buffer size
const DEFAULT_BUFFSIZE = 32768 // default buffer size for reader
const DrawTextHook = 2 // Z3S5 Machine draw text in vram - unused in Z3S5 Lisp
const LastHook = 16 // *never used*
const LoadHook = 4 // Z3S5 Machine editor load hook - unused in Z3S5 Lisp
const LoadTextHook = 5 // Z3S5 Machine editor load text hook - unused in Z3S5 Lisp
const PrintHook = 3 // Z3S5 Machine print text in editor - unused in Z3S5 Lisp
const SND_CLICK = 3
const SND_CONFIRM = 5
const SND_ERROR = 0
const SND_INFO = 6
const SND_OKAY = 4
const SND_READY = 2
const SND_START = 1
const SaveHook = 6 // Z3S5 Machine editor save hook - unused in Z3S5 Lisp
const SaveTextHook = 7 // Z3S5 Machine editor save text hook - unused in Z3S5 Lisp
const ScrollDownPost = 14 // Z3S5 Machine after scrolling down - unused in Z3S5 Lisp
const ScrollDownPre = 13 // Z3S5 Machine before scrolling down - unused in Z3S5 Lisp
const ScrollUpPost = 12 // Z3S5 Machine after scrolling up - unused in Z3S5 Lisp
const ScrollUpPre = 11 // Z3S5 Machine before scrolling up - unused in Z3S5 Lisp
const SetCursorHook = 1 // Z3S5 Machine set cursor position in vram - unused in Z3S5 Lisp
Constants for hooks. These are used by various modules and introduce a flat global dependency on github.com/rasteric/hooks. They are defined individually in order to prevent insertion errors. Except for LastHook, the numbers are fixed for all future and can never change or be reused.
const ShutdownHook = 9 // just before the system shuts down
const SlowIRQHook = 8 // general slow IRQ (ca. 1 sec. intervals)
const StartupHook = 15 // called after the system has been started (all init files loaded)
const SuperslowIRQHook = 10 // very slow (only every few minutes)
Variables ¶
var AppendSym = NewSym("append")
var ApplySym = NewSym("apply")
var ArraySym = NewSym("array")
var BackQuoteSym = NewSym("`")
var BoxedBlob = NewSym("blob")
Boxed types (mostly handled externally).
var BoxedDecimal = NewSym("dec.num")
var ColorBlack = Color{0, 0, 0, 255, true}
var ColorWhite = Color{255, 255, 255, 255, true}
var CommaAtSym = NewSym(",@")
var CommaSym = NewSym(",")
var CondSym = NewSym2("cond", true)
var ConsSym = NewSym("cons")
var DotSym = NewSym(".")
var EofToken error = io.EOF
EofToken is a token which represents the end of file.
var ErrNoSuchPermission = errors.New("security violation - missing permission")
var ErrPermissionManagerFail = errors.New("internal permission manager failure")
var ErrSecurityViolation = errors.New("security violation")
var ErrUnknownPermission = errors.New("unknown permission")
var ErrorHandler = NewSym("*error-handler*")
var ErrorPrinter = NewSym("*error-printer*")
var FullPermissions = Permissions{ AllowUnprotect: true, AllowProtect: true, LoadPrelude: true, LoadUserInit: true, Interactive: true, AllowFileRead: true, AllowFileWrite: true, }
FullPermissions are the default full permissions of a machine, allowing full access to all resources of the machine.
var FutureSym = NewSym2("future", true)
var HashSym = NewSym("#")
var LambdaSym = NewSym2("lambda", true)
var LeftParenSym = NewSym("(")
var ListSym = NewSym("list")
var MacroSym = NewSym2("macro", true)
var Number0 = goarith.AsNumber(0)
var Number1 = goarith.AsNumber(1)
var Prelude = strings.Replace(`
(setq defmacro
(macro (name args &rest body)
~(progn (setq ,name (macro ,args ,@body))
',name)))
(defmacro defun (name args &rest body)
~(progn (setq ,name (lambda ,args ,@body))
',name))
(defun caar (x) (car (car x)))
(defun cadr (x) (car (cdr x)))
(defun cdar (x) (cdr (car x)))
(defun cddr (x) (cdr (cdr x)))
(defun caaar (x) (car (car (car x))))
(defun caadr (x) (car (car (cdr x))))
(defun cadar (x) (car (cdr (car x))))
(defun caddr (x) (car (cdr (cdr x))))
(defun cdaar (x) (cdr (car (car x))))
(defun cdadr (x) (cdr (car (cdr x))))
(defun cddar (x) (cdr (cdr (car x))))
(defun cdddr (x) (cdr (cdr (cdr x))))
(defun not (x) (eq? x nil))
(defun cons? (x) (not (atom? x)))
(defun print (x) (prin1 x) (terpri) x)
(defun identity (x) x)
(defun feature? (sym)
(if (member sym *reflect*) t nil))
(setq
= eql?
null? not
setcar rplaca
setcdr rplacd)
(defun > (x y) (< y x))
(defun >= (x y) (not (< x y)))
(defun <= (x y) (not (< y x)))
(defun /= (x y) (not (= x y)))
(defun equal? (x y)
(cond ((atom? x) (eql? x y))
((atom? y) nil)
((equal? (car x) (car y)) (equal? (cdr x) (cdr y)))))
(defmacro if (test then &rest else)
~(cond (,test ,then)
,@(cond (else ~((t ,@else))))))
(defmacro when (test &rest then)
~(cond (,test ,@then)
,@(cond (t ~((t (void)))))))
(defmacro unless (test &rest then)
~(cond ((not ,test) ,@then)
,@(cond (t ~((t (void)))))))
;; original definition returns nil instead of void:
;; (defmacro when (test &rest body)
;; ~(cond (,test ,@body)))
(defmacro let (args &rest body)
((lambda (vars vals)
(defun vars (x)
(cond (x (cons (if (atom? (car x))
(car x)
(caar x))
(vars (cdr x))))))
(defun vals (x)
(cond (x (cons (if (atom? (car x))
nil
(cadar x))
(vals (cdr x))))))
~((lambda ,(vars args) ,@body) ,@(vals args)))
nil nil))
(defmacro letrec (args &rest body) ; (letrec ((v e) ...) body...)
(let (vars setqs)
(defun vars (x)
(cond (x (cons (caar x)
(vars (cdr x))))))
(defun sets (x)
(cond (x (cons ~(setq ,(caar x) ,(cadar x))
(sets (cdr x))))))
~(let ,(vars args) ,@(sets args) ,@body)))
(defun _append (x y)
(if (null? x)
y
(cons (car x) (_append (cdr x) y))))
(defmacro append (x &rest y)
(if (null? y)
x
~(_append ,x (append ,@y))))
(defmacro and (x &rest y)
(if (null? y)
x
~(cond (,x (and ,@y)))))
(defun mapcar (x f)
(and x (cons (f (car x)) (mapcar (cdr x) f))))
(defmacro or (x &rest y)
(if (null? y)
x
~(cond (,x)
((or ,@y)))))
(defun list? (x)
(or (null? x) (cons? x))) ; NB (list? (lambda (x) (+ x 1))) => nil
(defun memq (key x)
(cond ((null? x) nil)
((eq? key (car x)) x)
(t (memq key (cdr x)))))
(defun member (key x)
(cond ((null? x) nil)
((equal? key (car x)) x)
(t (member key (cdr x)))))
(defun assq (key alist)
(cond (alist (let ((e (car alist)))
(if (and (cons? e) (eq? key (car e)))
e
(assq key (cdr alist)))))))
(defun assoc (key alist)
(cond (alist (let ((e (car alist)))
(if (and (cons? e) (equal? key (car e)))
e
(assoc key (cdr alist)))))))
(defun _nreverse (x prev)
(let ((next (cdr x)))
(setcdr x prev)
(if (null? next)
x
(_nreverse next x))))
(defun nreverse (list) ; (nreverse '(a b c d)) => (d c b a)
(cond (list (_nreverse list nil))))
(defun list-last (list)
(if (atom? (cdr list))
list
(list-last (cdr list))))
(defun nconc (&rest lists)
(if (null? (cdr lists))
(car lists)
(if (null? (car lists))
(apply nconc (cdr lists))
(setcdr (list-last (car lists))
(apply nconc (cdr lists)))
(car lists))))
(defmacro while (test &rest body)
(let ((loop (gensym)))
~(letrec ((,loop (lambda () (cond (,test ,@body (,loop))(t (void))))))
(,loop))))
(defmacro dolist (spec &rest body) ; (dolist (name list [result]) body...)
(let ((name (car spec))
(list (gensym)))
~(let (,name
(,list ,(cadr spec)))
(while ,list
(setq ,name (car ,list))
,@body
(setq ,list (cdr ,list)))
,@(if (cddr spec)
~((setq ,name nil)
,(caddr spec))))))
(defmacro dotimes (spec &rest body) ; (dotimes (name count [result]) body...)
(let ((name (car spec))
(count (gensym)))
~(let ((,name 0)
(,count ,(cadr spec)))
(while (< ,name ,count)
,@body
(setq ,name (+ ,name 1)))
,@(if (cddr spec)
~(,(caddr spec))))))
(setq *mutable-toplevel-symbols* (dict))
(defun declare-unprotected (sym)
(set *mutable-toplevel-symbols* sym t))
(setq *volatile-toplevel-symbols* (dict))
(defun declare-volatile (sym)
(set *volatile-toplevel-symbols* sym t))
(declare-volatile '*volatile-toplevel-symbols*)
(declare-volatile '*mutable-toplevel-symbols*)
(declare-unprotected 'vars) ; fixes unclean macro definitions using defun
(declare-unprotected 'vals) ; so these do not get protected later
(declare-unprotected 'sets) ; unbind does not do the job since init sequence uses the macros later
`, "~", "`", -1)
Prelude is an initialization script of Lisp. Each "~" is replaced by "`" at runtime.
var ProgNSym = NewSym2("progn", true)
var QuasiquoteSym = NewSym2("quasiquote", true)
var QuoteSym = NewSym2("quote", true)
var ReflectSym = NewSym("*reflect*")
var RestSym = NewSym("&rest")
var RestrictedPermissions = Permissions{ AllowUnprotect: false, AllowProtect: false, LoadPrelude: true, LoadUserInit: true, Interactive: false, AllowFileRead: false, AllowFileWrite: false, }
SafeSilentPermissions are minimal permissions without sound, graphics, and file access but with prefs read access and console.
var RightParenSym = NewSym(")")
var SetqSym = NewSym2("setq", true)
var SingleQuoteSym = NewSym("'")
var TaskSym = NewSym2("systask", true)
var UnquoteSplicingSym = NewSym("unquote-splicing")
var UnquoteSym = NewSym("unquote")
var Void = NewSym("<void>")
Functions ¶
func AsLispBool ¶
AsLispBool returns a given Go bool as a Lisp bool, i.e., using Nil for false.
func ConvertIntsToNumbers ¶
func ConvertIntsToNumbers(a []any)
ConvertIntsToNumbers converts any Int64 integer values in a slice to goarith.Int64 values, modifying the array. The int64 values in the array can afterwards be used in Lisp.
func ConvertNumbersToInts ¶
func ConvertNumbersToInts(a []any)
ConvertNumbersToInts converts any goarith.Int32 and goarith.Int64 values in a slice of interface{} values to Int64, modifying the array. The array can no longer be used for representing Lisp numbers afterwards.
func DictToArray ¶
dictToArray converts a dict (Go map) to an array.
func GetGID ¶
func GetGID() uint64
GetGID returns the current goroutine's ID. This should not be abused and may break. But who cares! CHECK DANGER UNSAFE
func ListToArray ¶
ListToArray converts a list into an array (Go slice).
func NewClosure ¶
NewClosure constructs a Closure.
func ReverseArray ¶
reverse array returns an array reversed as copy
func Same ¶
Same is true if two Lisp interface{} have the same values, false otherwise. This is needed because map[interface{}]interface{} cannot be compared!
func SleepHiRes ¶
SleepNS blocks for duration and then returns. This function busy loops over a high precision timer.
func Str2 ¶
Str2 returns a textual representation of any Lisp expression x. If quoteString is true, any strings in the expression are represented with enclosing quotes respectively.
func ToMaybeUInt64 ¶
ToMaybeUInt64 attempts to convert a value to uint64
Types ¶
type Arg ¶
type Arg struct { // Level is a nesting level of the lexical scope. // 0 for the innermost scope. Level int // Offset is an offset of the variable within the frame of the Level. // 0 for the first variable within the frame. Offset int // Sym is a symbol which represented the variable before compilation. Symbol *Sym }
Arg represents a bound variable in a compiled lambda/macro expression. It is constructed with &Arg{level, offset, symbol}.
func (*Arg) Externalize ¶
Externalize returns the external representation of the argument (assuming it's name has been resolved in higher environments).
func (*Arg) GetValue ¶
GetValue gets a value from the location corresponding to the variable x within an environment env.
func (*Arg) GetValueSafe ¶
GetValueSafe gets the value from the location corresponding to the variable x within an environment env and returns true, or it returns nil and false if the value cannot be found in env.
type BasicAudio ¶
type BasicAudio struct { }
BasicAudio plays a small number of predefined system sounds.
func NewBasicAudio ¶
func NewBasicAudio() *BasicAudio
func (*BasicAudio) SetVolume ¶
func (audio *BasicAudio) SetVolume(vol float64)
func (*BasicAudio) SystemSound ¶
func (audio *BasicAudio) SystemSound(snd int)
type BasicEditor ¶
type BasicEditor struct {
// contains filtered or unexported fields
}
BasicEditor provides only basic string entering for a REPL.
func NewBasicEditor ¶
func NewBasicEditor() *BasicEditor
func (*BasicEditor) Color ¶
func (ed *BasicEditor) Color(bg bool) Color
func (*BasicEditor) EndInput ¶
func (ed *BasicEditor) EndInput() (string, bool)
func (*BasicEditor) EndInputCallback ¶
func (ed *BasicEditor) EndInputCallback() func()
func (*BasicEditor) ResetColor ¶
func (ed *BasicEditor) ResetColor()
func (*BasicEditor) SetColor ¶
func (ed *BasicEditor) SetColor(bg bool, color Color)
func (*BasicEditor) StartInput ¶
func (ed *BasicEditor) StartInput(cb func())
type BasicRuntime ¶
type BasicRuntime struct {
// contains filtered or unexported fields
}
BasicRuntime is a minimal runtime system that only uses the console and basic sounds. It implements the Runtime interface.
func NewBasicRuntime ¶
func NewBasicRuntime(perm Permissions) *BasicRuntime
func (*BasicRuntime) EditorInterface ¶
func (rt *BasicRuntime) EditorInterface() Editing
func (*BasicRuntime) Enqueue ¶
func (rt *BasicRuntime) Enqueue(f func())
func (*BasicRuntime) Perm ¶
func (rt *BasicRuntime) Perm() Permissions
func (*BasicRuntime) RequestShutdown ¶
func (rt *BasicRuntime) RequestShutdown(errcode int)
func (*BasicRuntime) SetPerm ¶
func (rt *BasicRuntime) SetPerm(p Permissions) error
func (*BasicRuntime) SoundInterface ¶
func (rt *BasicRuntime) SoundInterface() Audio
type Boxed ¶
Boxed is the type of an opaque, non-writable Lisp object. It holds the actual object as interface{} and manages the Lisp type and printing.
func ExpectBoxed ¶
ExpectBoxed returns a boxed value of type sort if a is one and true, nil and false otherwise.
func MustGetBoxed ¶
MustGetBoxed returns a boxed value of type sort or panics.
type BoxedArray ¶
type BoxedArray struct {
// contains filtered or unexported fields
}
BoxedArray is a synchronized array of boxed items.
func NewBoxedArray ¶
func NewBoxedArray() *BoxedArray
NewBoxedArray returns a new empty array for boxed items.
func (*BoxedArray) Range ¶
func (a *BoxedArray) Range(f func(i int, obj *Boxed) bool)
Range is used to traverse a boxed array with a function that takes an index and an object and returns bool. If the function returns false, then the traversal stops. Otherwise it continues until the whole array has been traversed.
func (*BoxedArray) Remove ¶
func (a *BoxedArray) Remove(obj *Boxed)
Remove a boxed item from the array.
type BufferedReader ¶
type BufferedReader struct {
// contains filtered or unexported fields
}
BufferedReader is a buffered reader.
func NewBufferedReader ¶
func NewBufferedReader(reader io.Reader) *BufferedReader
NewBufferedReader returns a buffered reader based on an io.Reader.
func (*BufferedReader) BuffIOReader ¶
func (r *BufferedReader) BuffIOReader() *bufio.Reader
BuffIOReader returns the bufio.Reader encapsulated in the BufferedReader.
type BuiltInFunc ¶
type BuiltInFunc struct { Func // contains filtered or unexported fields }
BuiltInFunc represents a built-in function.
func NewBuiltInFunc ¶
func NewBuiltInFunc(name string, carity int, body func([]any) any) *BuiltInFunc
NewBuiltInFunc constructs a BuiltInFunc.
func (*BuiltInFunc) EvalWith ¶
func (x *BuiltInFunc) EvalWith(interp *Interp, arg *Cell, interpEnv *Cell) any
EvalWith invokes the built-in function with a list of actual arguments.
func (*BuiltInFunc) Externalize ¶
func (x *BuiltInFunc) Externalize(interp *Interp, env *Cell) string
Externalize returns a textual representation suitable for reading.
func (*BuiltInFunc) String ¶
func (x *BuiltInFunc) String() string
String returns a textual representation of the BuiltInFunc.
type Cell ¶
Cell represents a cons cell. &Cell{car, cdr} works as the "cons" operation.
func ArrayToList ¶
ArrayToList converts an array (Go slice) to a list.
func ConvertTimeToDateList ¶
ConvertTimeToDateList converts a time.Time value into a Lisp datelist.
func StrArrayToList ¶
StrArrayToList converts an array of strings (not a Lisp object) to a list of strings (an admissible Lisp object).
type Closure ¶
Closure represents a compiled lambda expression with its own environment.
func (*Closure) Externalize ¶
Externalize returns an external representation suitable for reading.
type Editing ¶
type Editing interface { StartInput(cb func()) // called to start the input, callback is called when input ends EndInput() (string, bool) // called when input ends EndInputCallback() func() // the callback called when the input ends Print(s string) (int, int) // print s in the current color, return number of lines scrolled and number of lines printed SetColor(bg bool, color Color) // set the current color Color(bg bool) Color // get the current color ResetColor() // reset both foreground and background color to default }
type EvalError ¶
EvalError represents an error in evaluation.
func NewEvalError ¶
NewEvalError constructs an EvalError.
func NewNotVariableError ¶
NewNotVariableError constructs an EvalError which indicates an absence of variable.
func NewProtectedVariableError ¶
NewProtectedVariableError constructs an EvalError which indicates that the given variable is protected against global mutation.
type Externalizable ¶
type Func ¶
type Func struct { // Carity is a number of arguments, made negative if the func has &rest. Carity int // Args is the formal argument list of the function when it was originally defined, or nil // for a builin function. This is used by Externalize. Args *Cell }
Func is a common base type of Lisp functions.
type Future ¶
type Future struct { // Chan is a channel which transmits a pair of result and error. // The pair is represented by Cell. Chan <-chan Cell // Result is a pair of the result (in a narrow meaning) and the error. Result Cell // Lock is an exclusive lock to receive the result at "force". Lock sync.Mutex }
Future represents a "promise" for future/force.
type Interp ¶
type Interp struct {
// contains filtered or unexported fields
}
Interp represents a core of the interpreter.
func NewInterp ¶
NewInterp constructs an interpreter and sets built-in functions etc. as the global values of symbols within the interpreter.
func (*Interp) Boot ¶
Boot loads the standard prelude and any other init files and ensures that the interpreter is in a ready state.
func (*Interp) Break ¶
func (interp *Interp) Break()
Break attempts to globally cancel a running process and restart the read-eval-print loop using StartREPL. It is like a soft reset function and would usually be bound to a function (break).
func (*Interp) CanExternalize ¶
CanExternalize returns true if the value in a can be externalized, false otherwise. Changes must be reflected in Externalize.
func (*Interp) DefaultPrintError ¶
DefaultPrintError is the default error printer that simply outputs the error string.
func (*Interp) Define_Base ¶
func (interp *Interp) Define_Base()
Define_Base defines basic Lisp functions that should work on any platform.
func (*Interp) Define_Console ¶
func (interp *Interp) Define_Console()
Define_Console defines console-related commands, where the console is a OS terminal, not an editor console based on the virtual machine in PC.
func (*Interp) Define_Decimal ¶
func (interp *Interp) Define_Decimal()
Define_Decimal defines decimal arithmetics primitives with prefix 'dec. These can be used for finance and banking applications that require fixed precision and correct rounding.
func (*Interp) Define_FileIO ¶
func (interp *Interp) Define_FileIO()
func (*Interp) Define_Float ¶
func (interp *Interp) Define_Float()
Define_Float defines floating point related functions with prefix fl.
func (*Interp) Define_Ling ¶
func (interp *Interp) Define_Ling()
func (*Interp) Define_StyledText ¶
func (interp *Interp) Define_StyledText()
func (*Interp) EndLineInput ¶
func (interp *Interp) EndLineInput()
func (*Interp) EvalFile ¶
EvalFile evaluates a file, returns true if no error has occurred and false if an error has occurred.
func (*Interp) EvalString ¶
EvalString evaluates a string and returns the result or an error. If string contains more than one expression, then only the first expression is executed. To prevent this, you may wrap several expressions into (progn expr ...). If the expression is empty, io.EOF error is returned. Use Str(result) to print the result in human-readable form.
func (*Interp) ExpandMacros ¶
ExpandMacros expands macros and quasi-quotes in x up to count nestings.
func (*Interp) ExpectInts ¶
ExpectInts returns a slice of n ints decoded from a[offset], or panics with an error.
func (*Interp) Externalize ¶
Return a representation of a that is suitable for reading. Like Str and derived directly from it - see externalize5 and externalizeListBody -, but this procedure creates externalizable representations for all arguments. Changes must be reflected in CanExternalize.
func (*Interp) GetGlobalVar ¶
GetGlobalVar gets a global value of symbol sym within the interpreter.
func (*Interp) HandleError ¶
HandleError attempts to handle the error by invoking *error-handler* if it is defined. If there is no error handler or an error occurs in it, then the default error printer is called and Void, false is returned. If the error is handled successfuly, the handler's result and true is returned.
func (*Interp) InputCond ¶
InputCond returns a pointer to an sync.Cond condition used for waiting for input. This is used for asynchronously signaling EndInput.
func (*Interp) InputLock ¶
InputLock returns a pointer to a mutex used for locking on certain input conditions. It is recommended not to use this mutex unless you know what you're doing.
func (*Interp) Lock ¶
func (interp *Interp) Lock()
Lock locks the interpreter's internal RWMutex. Be careful not to create deadlocks using this mechanism and bear in mind that some calls internally use this mutex.
func (*Interp) MaybeLoadUserInit ¶
MaybeLoadUserInit attempts to load the user init file if it exists in the local directory and if the permission is available.
func (*Interp) MustParseBlobArgs ¶
MustParseBlobArgs parses the Lisp arguments for a blob and optional lower and upper bound. If the offset and upper bound are not provided, 0 and the length of the blob are used.
func (*Interp) Print ¶
Print outputs a string according using the runtime EditorInterface Print function. This is equivalent to using (out datum) on the Lisp side.
func (*Interp) PrintError ¶
PrintError prints the given error using the *error-printer* global variable if it has been set. The variable *error-printer* must contain a closure that takes an error or string as argument. If *error-printer* is unbound, then the built-in error printer is called.
func (*Interp) RLock ¶
func (interp *Interp) RLock()
RLock read-locks the interpreter's internal RWMutex. Be careful not to create deadlocks using this mechanism and bear in mind that some calls internally use this mutex.
func (*Interp) RUnlock ¶
func (interp *Interp) RUnlock()
RUnlock unlocks a read-lock of the interpreter's internal RWMutex.
func (*Interp) Run ¶
Run executes REPL (Read-Eval-Print Loop). It returns false if REPL was ceased by an error. It returns true if REPL was finished normally.
func (*Interp) Runtime ¶
Runtime returns the runtime support system provided when a new interpreter was created, as an unrestricted any interface, so the client can type cast it to whatever runtime structure they use.
func (*Interp) SafeEval ¶
SafeEval evaluates a Lisp expression in a given environment env and returns the result and nil. If an error happens, it returns Nil and the error
func (*Interp) SetGlobalVar ¶
SetGlobalVar sets a global value of symbol sym within the interpreter.
func (*Interp) SetInteractive ¶
SetInteractive sets the Lisp *interactive-session* global variable to indicate a session is interactive or not.
func (*Interp) StartREPL ¶
func (interp *Interp) StartREPL()
StartREPL marks the start of the line input in the current editor. The line can then be retrieved with EndLineInput for use in the Repl loop.
func (*Interp) Streams ¶
Streams returns a pointer to a sync.Map containing the i/o streams managed by the interpreter.
func (*Interp) UnbindGlobalVar ¶
UnbindGlobalVar removes the value of symbol, making the symbol unbound (not defined).
type Lambda ¶
Lambda represents a compiled lambda expression (within another function).
func (*Lambda) Externalize ¶
Externalize returns a readable external representation of the lambda term.
type Macro ¶
type Macro struct { Func // contains filtered or unexported fields }
Macro represents a compiled macro expression.
func (*Macro) ExpandWith ¶
ExpandWith expands the macro with a list of actual arguments.
func (*Macro) Externalize ¶
Externalize returns a readable external representation of the macro.
type Permissions ¶
type Permissions struct { AllowUnprotect bool AllowProtect bool LoadPrelude bool LoadUserInit bool Interactive bool AllowFileRead bool AllowFileWrite bool }
func NewPermissions ¶
func NewPermissions(current Permissions, perms []string) (Permissions, error)
NewPermissions creates a set of permissions from an array of symbolic strings. The permissions must be as restrictive or more restictive as the current permissions, or ErrSecurityViolation is returned.
func (Permissions) Set ¶
func (p Permissions) Set(perm string, v any) (Permissions, error)
Set sets a permission to the given value, returns an error if the permission cannot be changed. Permissions can only be changed from less secure to more secure, not vice versa, where the security hierarchy is hardcoded.
func (*Permissions) Strings ¶
func (p *Permissions) Strings() []string
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader represents a reader of Lisp expressions.
type Runtime ¶
type Runtime interface { EditorInterface() Editing // return the editor interface SoundInterface() Audio // return the audio interface Perm() Permissions // return the current permissions of the interpreter SetPerm(Permissions) error // set the current permissions, may return an error if not allowed RequestShutdown(errcode int) // request a shutdown of the interpreter - but it is not guaranteed Enqueue(func()) // enqueue an arbitrary function in a sequential queue - supposed to be GUI safe }
type Seeker ¶
type Seeker struct {
// contains filtered or unexported fields
}
Seeker is a minor abstraction wrapper for io.Seeker.
type Source ¶
type Source struct { Sort int // the type of the source Path string // path to the source file, URL, etc. LineNo int // line number (if applicable) Line string // the current line (used sometimes by the reader) }
func NewFileSource ¶
func NewInternalSource ¶
type Stream ¶
type Stream struct { LispReader *Reader LispWriter *Writer LispSeeker *Seeker LispWriterAt *WriterAt BuffReader *BufferedReader }
Stream is a Lisp wrapper for a lisp stream, reader and writer. It is used in combination with the FileManager to manage i/o streams.
type Sym ¶
Sym represents a symbol (or an expression keyword) in Lisp. &Sym{name, false} constructs a symbol which is not interned yet.
func NewSym2 ¶
NewSym2 constructs an interned symbol (or an expression keyword if isKeyword is true on its first construction) for name.
func (*Sym) IsInterned ¶
IsInterned returns true if sym is interned.
type ValueHolder ¶
ValueHolder is a miscellaneous structure to hold interface{} values with symbols as keys. The additional indirection is tolerated to avoid having to use two map lookups, one for the value and one for the Protected feature. Performance: The performance impact should be analyzed.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is the counterpart to Reader for writing lisp expressions to streams.
type WriterAt ¶
type WriterAt struct {
// contains filtered or unexported fields
}
WriterAt is a writer that can write to particular positions.
func NewWriterAt ¶
NewWriterAt creates a new WriterAt for writing to particular positions.
func (*WriterAt) IOWriterAt ¶
IOWriterAt returns the wrapped io.writerat in this stream.