gsh/evaluator/evaluator
The evaluator module is the beating heart of the GSH REPL.
Because Gleam is statically typed and compiled, we cannot evaluate raw AST
dynamically like Elixir’s IEx. Instead, this module takes the user’s input,
combines it with all previous session state (imports, bindings, types),
and generates a temporary gsh_eval.gleam file.
Crucially, this is where the “Side-Effect Magic Caching” happens. Every
variable assignment is wrapped in a check against the Erlang Process Dictionary,
ensuring that let x = io.println("test") only prints once, even as the
file is re-compiled for subsequent REPL prompts.
Values
pub fn evaluate(
input: String,
bindings: List(binding.Binding),
imports: List(String),
types: List(String),
functions: List(String),
) -> result.Evaluation
The main entry point for code evaluation.
- Analyzes the input to determine if it is an import, type, function, binding, or expression.
- Generates the full source code for a temporary Gleam module.
- Writes the file to disk and passes it to the
runnerto be compiled and executed. - Returns the result, updating the shell state if new bindings/imports were successfully evaluated.