| Engine | R Documentation |
Provides class-based organization for tokenization, parsing, macro expansion, evaluation, and environment management.
new()Initialize engine components and base environment.
Engine$new( coverage_tracker = NULL, load_prelude = TRUE, disable_tco = NULL, disable_constant_folding = NULL, disable_optimizations = NULL, disable_arithmetic_infix = NULL, disable_bytecode = NULL, r_packages = "search_path" )
coverage_trackerOptional CoverageTracker instance to enable coverage tracking from the start. If provided, coverage will be tracked during stdlib loading. Intended for internal development use.
load_preludeLogical. If TRUE (the default), loads prelude modules during initialization. Set to FALSE to create a bare engine with only builtins — useful for testing or when you want to import specific modules.
disable_tcoOptional logical. If TRUE, disables self-tail-call optimization
in the compiler, preserving natural call stacks for debugging. Defaults to NULL,
which inherits from global option getOption("arl.disable_tco", FALSE).
disable_constant_foldingOptional logical. If TRUE, disables compile-time
constant folding, forcing all expressions to be evaluated at runtime. Useful for
testing that builtins match R semantics. Defaults to NULL, which inherits from
global option getOption("arl.disable_constant_folding", FALSE).
disable_optimizationsOptional logical. If TRUE, disables all non-essential
compiler optimizations (constant folding, TCO, dead code elimination, strength
reduction, identity elimination, truthiness optimization, begin simplification,
and boolean flattening). Individual toggles like disable_tco and
disable_constant_folding are applied after this and can override it.
Defaults to NULL, which inherits from global option
getOption("arl.disable_optimizations", FALSE).
disable_arithmetic_infixLogical; if TRUE, disable 2-arg arithmetic infix compilation.
disable_bytecodeLogical; if TRUE, disable bytecode compilation of cached modules.
r_packagesControls which R packages are visible to Arl code.
"search_path" (default) tracks R's search() dynamically;
a character vector pins a fixed set; NULL exposes only baseenv().
read()Tokenize and parse source into expressions. The format returned by this method is not guaranteed to be stable across package versions.
Engine$read(source, source_name = NULL)
sourceCharacter string containing Arl source.
source_nameOptional source name for error reporting.
A list of parsed Arl expressions (R language objects).
write()Convert an Arl expression to its string representation. Inverse of read(). The format returned by this method is not guaranteed to be stable across package versions.
Engine$write(expr)
exprArl expression (symbol/call/atomic value).
A character string of the Arl source representation.
eval()Evaluate one or more expressions.
Engine$eval(expr, ..., env = NULL)
exprArl expression (symbol/call/atomic value).
...Additional Arl expressions to evaluate (variadic).
envOptional environment or Env used as the engine base.
The result of the last evaluated expression.
eval_text()Read and evaluate Arl source text. Convenience wrapper around
read() and eval().
Engine$eval_text(text, env = NULL, source_name = "<eval>")
textCharacter string of Arl code to read/eval.
envOptional environment or Env used as the engine base.
source_nameOptional source name for error reporting.
The result of the last evaluated expression.
eval_string()Alias for eval_text().
Engine$eval_string(text, env = NULL, source_name = "<eval>")
textCharacter string of Arl code to read/eval.
envOptional environment or Env used as the engine base.
source_nameOptional source name for error reporting.
The result of the last evaluated expression.
load_file_in_env()Load and evaluate an Arl source file in the given environment. Definitions
and imports in the file are visible in env. To evaluate in an
isolated child scope, create one explicitly:
load_file_in_env(path, new.env(parent = env)).
Engine$load_file_in_env(path, env = NULL, cache = TRUE)
pathFile path to load.
envOptional environment or Env used as the engine base.
cacheLogical; if TRUE (the default), use the module cache.
The result of the last evaluated expression (invisibly).
macroexpand()Expand macros in an expression. With depth = NULL (the default),
fully and recursively expand all macros. With depth = N, expand
only the top-level macro up to N times without walking into subexpressions.
Engine$macroexpand(expr, env = NULL, depth = NULL, preserve_src = FALSE)
exprArl expression (symbol/call/atomic value).
envOptional environment or Env used as the engine base.
depthNumber of expansion steps (NULL for full expansion).
preserve_srcLogical; keep source metadata when macroexpanding.
inspect_compilation()Inspect expansion and compilation for debugging. Parse text, expand macros in env, then compile to R. Returns parsed AST, expanded form, compiled R expression, and deparsed R code so you can see exactly what an Arl program becomes.
Engine$inspect_compilation(text, env = NULL, source_name = "<inspect>")
textCharacter; Arl source (single expression or multiple).
envEnvironment or NULL (use engine env). Must have macros/stdlib if needed.
source_nameName for parse errors.
List with parsed (first expr), expanded,
compiled (R expr or NULL), compiled_deparsed
(character, or NULL).
help()Show help for a topic.
Engine$help(topic, env = NULL, package = NULL)
topicHelp topic as a single string.
envOptional environment/Env to resolve Arl bindings against.
packageOptional package name (string or symbol) to force R help lookup in a specific package.
Help text (invisibly), or NULL if topic not found.
repl()Start the Arl REPL using this engine.
Engine$repl()
NULL (invisibly); called for side effects.
enable_coverage()Enable coverage tracking.
Creates a coverage tracker and installs it in the eval context. Should be called before running code you want to track.
Engine$enable_coverage()
The engine (invisibly), for method chaining.
disable_coverage()Disable coverage tracking.
Engine$disable_coverage()
The engine (invisibly), for method chaining.
get_coverage()Get coverage data as a data frame.
Engine$get_coverage()
A data frame with columns file, total_lines,
covered_lines, and coverage_pct (one row per tracked file),
with a "total" attribute containing aggregate stats.
Returns NULL if coverage tracking is not enabled.
reset_coverage()Reset coverage data.
Engine$reset_coverage()
The engine (invisibly), for method chaining.
get_env()Get the top-level R environment backing this engine.
Engine$get_env()
An R environment.
define()Define a binding in the engine's top-level environment. This is the supported way to inject R objects for use in Arl code.
Engine$define(name, value)
nameCharacter string; the binding name.
valueThe value to bind.
Invisible self (for chaining).
format_value()Format a value for display using the engine's formatter.
Engine$format_value(value)
valueValue to format.
Character string.
with_error_context()Run a function with source-tracking error context.
Engine$with_error_context(fn)
fnA zero-argument function to call.
The return value of fn.
print_error()Format and print an Arl error with source context.
Engine$print_error(e, file = stderr())
eA condition object.
fileConnection to print to (default stderr()).
NULL (invisibly); called for side effects.
engine <- Engine$new()
engine$eval_text("(+ 1 2 3)")
engine$eval_string("(+ 4 5)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.