On this page:
eval
Evaluator
Evaluator.make_  rhombus
Evaluator.make_  rhombus_  empty
Evaluator.import
Evaluator.instantiate
Evaluator.module_  is_  declared
Evaluator.current
8.16.0.1

11.4 Eval🔗ℹ

An evaluator is an interactive evaluation context. Each evaluator has its own set of bindings and, potentially, its own set of module declarations. A Rhombus read-eval-print loop (REPL) is backed by an evaluator, for example.

function

fun eval(seq :: Syntax,

         ~as_interaction: as_interaction :: Any = #false)

Evaluates a term, group, or multi-group sequence seq in the current evaluator.

If as_interaction is true, then seq is evaluated as if in a read-eval-print loop. Depending on the bindings of the current evaluator (as determined by Evaluator.current), that can be different that evaluating non-interaction top-level forms.

A suitable evaluator must have been created and installed as the value of the Evaluator.current context parameter, since the default evaluator is empty.

> parameterize { Evaluator.current: Evaluator.make_rhombus() }:

    eval('1 + 2')

3

annotation

Evaluator

Represents an evaluator for interactive evaluation via eval. An evaluator is installed as the current one using Evaluator.current, usually via parameterize.

Creates a fresh evaluator with rhombus imported.

Creates a fresh evaluator with the rhombus module attached, but not imported.

Imports mod into the current evaluator, even if the import definition form is not available in the evaluator itself.

function

fun Evaluator.instantiate(mod :: ModulePath,

                          export_name :: maybe(Symbol) = #false) :: Any

In the current evaluator, loads mod if it is not loaded already, and instantiates the run-time component of the loaded module if it is not instantiated already.

If export_name is #false, then the result is #void. Otherwise, the value exported by mod as export_name is returned, or an exception is thrown if no such export is available.

function

fun Evaluator.module_is_declared(mod :: ModulePath,

                                 ~load: load = #false) :: Boolean

Reports whether mod is declared in the current evaluator. If load is true, then the module may be loaded in the process of resolving mod, but no exception is thrown if mod refers to a submodule that does not exist (either because the enclosing module cannot be found or loaded, or because no submodule is declared within using the name in mod).

A context parameter for the current evaluator.