Documentation
¶
Overview ¶
Package eval provides evaluation and environment primitives.
Evaluation (R7RS 6.12) ¶
- eval: evaluate expression in given environment
- load: read and evaluate file contents
Environments ¶
- environment: create environment from import sets
- null-environment: create minimal R5RS environment
- scheme-report-environment: create R5RS environment
- interaction-environment: return current REPL environment
Use Extension or AddToRegistry to register all primitives.
Package eval provides eval and environment primitives.
Index ¶
- Variables
- func PrimCompile(mc machine.CallContext) error
- func PrimCurrentLoadDepth(mc machine.CallContext) error
- func PrimCurrentLoadDirectory(mc machine.CallContext) error
- func PrimCurrentLoadPath(mc machine.CallContext) error
- func PrimEnvironment(mc machine.CallContext) error
- func PrimEval(cc machine.CallContext) error
- func PrimExpand(cc machine.CallContext) error
- func PrimExpandOnce(cc machine.CallContext) error
- func PrimLoad(cc machine.CallContext) error
- func PrimMakeCompileTimeValue(mc machine.CallContext) error
- func PrimNullEnvironment(mc machine.CallContext) error
- func PrimSchemeReportEnvironment(mc machine.CallContext) error
- func PrimSyntaxLocalIdentifierAsBinding(cc machine.CallContext) error
- func PrimSyntaxLocalIntroduce(cc machine.CallContext) error
- func PrimSyntaxLocalValue(cc machine.CallContext) error
- func PrimSyntaxLocalValueImmediate(mc machine.CallContext) error
Constants ¶
This section is empty.
Variables ¶
var AddToRegistry = Builder.AddToRegistry
AddToRegistry registers all eval primitives.
var Builder = registry.NewRegistryBuilder(addPrimitives)
Builder aggregates all eval registration functions.
var ErrWileProfilesNotRegistered = werr.NewStaticError("wile profiles not registered")
ErrWileProfilesNotRegistered is returned when tryWileProfile dispatches on a (wile <name>) spec but no ProfileFactory has been registered.
var Extension = registry.NewDescribedExtension("eval", "Code evaluation: eval, load, include, macroexpand.", AddToRegistry)
Extension is the eval extension.
var ProfileFactory func(ctx context.Context, callerNS *environment.Namespace, profileName string) (*environment.Namespace, error)
ProfileFactory is the callback used by (environment '(wile <name>)) to construct a namespace for a named Wile profile. It is set by internal/bootstrap at init time (bootstrap cannot be imported here because bootstrap already imports this package). When nil, (wile <name>) specs return ErrWileProfilesNotRegistered.
Functions ¶
func PrimCompile ¶
func PrimCompile(mc machine.CallContext) error
PrimCompile implements the (compile) primitive. Compiles an expression and returns a zero-argument procedure (thunk) that, when called, executes the compiled code.
(compile expr) -> procedure
The expr can be either a syntax object or a datum (which will be converted to a syntax object automatically).
This is the final phase hook, completing the pipeline:
expand -> compile -> (execute via calling the returned thunk)
func PrimCurrentLoadDepth ¶
func PrimCurrentLoadDepth(mc machine.CallContext) error
PrimCurrentLoadDepth implements the (current-load-depth) primitive. Returns the current load stack depth (number of nested loads). Returns 0 when not inside a load call.
func PrimCurrentLoadDirectory ¶
func PrimCurrentLoadDirectory(mc machine.CallContext) error
PrimCurrentLoadDirectory implements the (current-load-directory) primitive. Returns the directory of the file currently being loaded, or #f if no file is being loaded (e.g., REPL).
func PrimCurrentLoadPath ¶
func PrimCurrentLoadPath(mc machine.CallContext) error
PrimCurrentLoadPath implements the (current-load-path) primitive. Returns the path of the file currently being loaded, or #f if no file is being loaded (e.g., REPL).
func PrimEnvironment ¶
func PrimEnvironment(mc machine.CallContext) error
func PrimEval ¶
func PrimEval(cc machine.CallContext) error
PrimEval implements the (eval) primitive. 1-arg form: (eval expr) — uses current namespace (interaction-environment). 2-arg form: (eval expr env) — uses the given environment.
With ParamCount: 1 and IsVariadic: true, all args arrive as a rest list in mc.Arg(0).
func PrimExpand ¶
func PrimExpand(cc machine.CallContext) error
PrimExpand implements the expand primitive. Fully expands a syntax object and returns the expanded syntax. (expand stx) -> expanded-stx
func PrimExpandOnce ¶
func PrimExpandOnce(cc machine.CallContext) error
PrimExpandOnce implements the expand-once primitive. Performs a single step of macro expansion and returns both the expanded syntax and a boolean indicating whether expansion occurred. (expand-once stx) -> (values expanded-stx did-expand?)
func PrimLoad ¶
func PrimLoad(cc machine.CallContext) error
PrimLoad implements the (load) primitive. Loads and evaluates a Scheme source file.
File resolution uses the same FileResolver as include, so load and include share the same search path priority:
LoadPathStack > LibraryRegistry > SCHEME_INCLUDE_PATH > CWD
func PrimMakeCompileTimeValue ¶
func PrimMakeCompileTimeValue(mc machine.CallContext) error
PrimMakeCompileTimeValue implements the make-compile-time-value primitive. Wraps a value for compile-time storage. (make-compile-time-value value) -> compile-time-value
This creates a CompileTimeValue wrapper around the given value. CompileTimeValue is used to distinguish regular runtime values from values that should be stored in the expand phase and accessed during macro expansion.
When syntax-local-value retrieves a CompileTimeValue, it automatically unwraps it to return the underlying value.
func PrimNullEnvironment ¶
func PrimNullEnvironment(mc machine.CallContext) error
PrimNullEnvironment implements the null-environment primitive. Returns an empty R5RS environment with no bindings.
func PrimSchemeReportEnvironment ¶
func PrimSchemeReportEnvironment(mc machine.CallContext) error
PrimSchemeReportEnvironment implements the (scheme-report-environment) primitive. Returns R5RS env.
func PrimSyntaxLocalIdentifierAsBinding ¶
func PrimSyntaxLocalIdentifierAsBinding(cc machine.CallContext) error
PrimSyntaxLocalIdentifierAsBinding implements the syntax-local-identifier-as-binding primitive. Marks an identifier as a binding site by adding the use-site scope. (syntax-local-identifier-as-binding id) -> id
This primitive adds the "use-site scope" to an identifier, marking it as a binding site. This is used in binding forms (like let, lambda) to ensure proper hygiene when the binding form is implemented as a macro.
When a macro introduces a binding form, the bound identifiers need the use-site scope to be properly distinguished from identifiers at the macro's definition site.
Use cases:
- Implementing custom binding forms as macros
- Ensuring proper hygiene for macro-generated bindings
- Creating hygienic versions of anaphoric macros
This primitive can only be called during macro expansion (when an ExpanderContext is set on the MachineContext with a use-site scope).
func PrimSyntaxLocalIntroduce ¶
func PrimSyntaxLocalIntroduce(cc machine.CallContext) error
PrimSyntaxLocalIntroduce implements the syntax-local-introduce primitive. Flips the introduction scope on a syntax object. (syntax-local-introduce stx) -> stx
This primitive toggles the "introduction scope" on a syntax object. The introduction scope is added to identifiers introduced by a macro. By flipping it, you can make an introduced identifier behave as if it came from the macro use site (or vice versa).
Use cases:
- Breaking hygiene intentionally (anaphoric macros)
- Making macro-introduced bindings visible at the use site
- Implementing advanced macro patterns like syntax-parameterize
This primitive can only be called during macro expansion (when an ExpanderContext is set on the MachineContext with an introduction scope).
func PrimSyntaxLocalValue ¶
func PrimSyntaxLocalValue(cc machine.CallContext) error
PrimSyntaxLocalValue implements the syntax-local-value primitive. Retrieves the compile-time value bound to an identifier in the expand phase. (syntax-local-value id) -> value
This primitive can only be called during macro expansion (when an ExpanderContext is set on the MachineContext). It looks up the identifier in the expand phase environment, respecting hygiene scopes.
If the binding is a CompileTimeValue, it returns the unwrapped value. This allows define-for-syntax bindings to be accessed from macro transformers.
func PrimSyntaxLocalValueImmediate ¶
func PrimSyntaxLocalValueImmediate(mc machine.CallContext) error
PrimSyntaxLocalValueImmediate implements (syntax-local-value/immediate id). Like syntax-local-value but does not chase rename-transformer chains. Wile does not currently have rename-transformers, so this behaves identically to syntax-local-value.
When rename-transformers are implemented, this function must NOT chase the transformer chain — it should return the transformer object directly. At that point, PrimSyntaxLocalValue and PrimSyntaxLocalValueImmediate must diverge.
Racket §12.4: syntax-local-value/immediate
Types ¶
This section is empty.