Documentation
¶
Overview ¶
Package writ is the high-level embedding API for the Writ Lisp.
Integers are arbitrary precision (int64 fast path, math/big otherwise). Floats are IEEE float64. Inexact division of large integers is float64 and may round. true, false, and nil are interned symbols; true and false are booleans; nil is not. Eval with the default unlimited step budget is not a sandbox. Native plugins are off until WithNativePlugins.
(+ 1 2) (def (add a b) (+ a b)) (let [x: 1] (+ x 2))
Index ¶
- func Check(src string) types.CheckResult
- type Option
- type Runtime
- func (rt *Runtime) AliasType(name string) (types.Type, bool)
- func (rt *Runtime) Apply(fn runtime.Value, args []runtime.Value) (runtime.Value, error)
- func (rt *Runtime) Check(src string) types.CheckResult
- func (rt *Runtime) CheckFile(path string) types.CheckResult
- func (rt *Runtime) Eval(src string) (runtime.Value, error)
- func (rt *Runtime) EvalFile(path string) (runtime.Value, error)
- func (rt *Runtime) Fire(event string, payload map[string]runtime.Value) error
- func (rt *Runtime) GetProp(path ...string) runtime.Value
- func (rt *Runtime) Lookup(name string) (runtime.Value, bool)
- func (rt *Runtime) RegisterAlias(name string, members ...string)
- func (rt *Runtime) RegisterBuiltin(name string, call runtime.Func, arrows ...types.Arrow) error
- func (rt *Runtime) RegisterEvent(name string, keys ...types.PayloadKey)
- func (rt *Runtime) RegisterPackage(name string, pkg runtime.Package)
- func (rt *Runtime) RegisterPrint()
- func (rt *Runtime) RegisterTypeAlias(name string, t types.Type)
- func (rt *Runtime) Reset()
- func (rt *Runtime) SetAfterError(fn func(error))
- func (rt *Runtime) SetProp(val runtime.Value, path ...string) error
- func (rt *Runtime) SetScheduler(s runtime.Scheduler)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(src string) types.CheckResult
Check type-checks src with a fresh runtime. print is registered so scripts that use it type-check the same way as `writ check`.
Types ¶
type Option ¶
type Option func(*Runtime)
Option configures a Runtime.
func WithAfterError ¶
WithAfterError sets a hook for errors from (after ...) callbacks.
func WithAllowAbsoluteImports ¶
func WithAllowAbsoluteImports() Option
WithAllowAbsoluteImports allows absolute import paths and paths that leave the importing script directory / search path (including "..").
func WithEvalLimit ¶
WithEvalLimit caps eval/expand steps across expand, eval, import, after, Fire, and Apply until the next public call resets the remaining budget. Zero (the default) means unlimited and is not a sandbox.
func WithNativePlugins ¶
func WithNativePlugins() Option
WithNativePlugins allows (import) of Go plugin files (.so/.dylib/.dll). Off by default. Plugins are never opened during Check.
func WithScheduler ¶
WithScheduler replaces the default time.AfterFunc scheduler.
func WithSearchPath ¶
WithSearchPath sets directories used to resolve import paths.
func WithStdout ¶
WithStdout sets the writer used by the print builtin if registered.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime evaluates scripts, holds the script store, and hosts packages. Public methods are safe for concurrent use.
func (*Runtime) Check ¶
func (rt *Runtime) Check(src string) types.CheckResult
Check type-checks src.
func (*Runtime) CheckFile ¶
func (rt *Runtime) CheckFile(path string) types.CheckResult
CheckFile type-checks a file.
func (*Runtime) Eval ¶
Eval compiles and evaluates src (boot forms only). Defs, macros, and handlers persist on this runtime until Runtime.Reset; later Eval calls expand using those macros. Redefining a function replaces it (clauses are not merged across calls). A name cannot be both a function and a macro. (on ...) handlers accumulate across Eval calls.
func (*Runtime) EvalFile ¶
EvalFile evaluates a file's boot forms. It does not call main. Persistence is the same as Runtime.Eval; call Runtime.Reset before reloading a file if (on ...) handlers should not stack.
func (*Runtime) RegisterAlias ¶
RegisterAlias names a closed union of exact strings for type display and host domain types.
func (*Runtime) RegisterBuiltin ¶
RegisterBuiltin adds a host function visible as a call head.
func (*Runtime) RegisterEvent ¶
func (rt *Runtime) RegisterEvent(name string, keys ...types.PayloadKey)
RegisterEvent declares an event for (on ...) and Runtime.Fire. If any events are registered, unknown event names are type errors.
func (*Runtime) RegisterPackage ¶
RegisterPackage installs an in-process package. (import "name") loads it without touching the filesystem.
func (*Runtime) RegisterPrint ¶
func (rt *Runtime) RegisterPrint()
RegisterPrint installs a print builtin that writes to stdout (or WithStdout).
func (*Runtime) RegisterTypeAlias ¶
RegisterTypeAlias names an arbitrary type.
func (*Runtime) Reset ¶
func (rt *Runtime) Reset()
Reset clears the script store, top-level env, macros, handlers, and import cache.
func (*Runtime) SetAfterError ¶
SetAfterError sets a hook for errors from (after ...) callbacks.
func (*Runtime) SetScheduler ¶
SetScheduler replaces the after scheduler.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
writ
command
|
|
|
example
|
|
|
nativehello
command
A native package for (import ...) via go build -buildmode=plugin.
|
A native package for (import ...) via go build -buildmode=plugin. |
|
Package parser reads Writ source into runtime values and pretty-prints it.
|
Package parser reads Writ source into runtime values and pretty-prints it. |
|
Package repl is an interactive evaluator for Writ source.
|
Package repl is an interactive evaluator for Writ source. |
|
Package runtime is the Writ value universe and evaluator.
|
Package runtime is the Writ value universe and evaluator. |
|
Package scanner tokenizes Writ source for the parser and for editors.
|
Package scanner tokenizes Writ source for the parser and for editors. |
|
Package types is Writ's type algebra and checker.
|
Package types is Writ's type algebra and checker. |