Mere REPL — written in Mere, running in the browser
Paste a Mere expression or a full file on the left and press Run. The Wasm module on this page tokenizes, parses, and evaluates your input — all written in Mere itself, no server round-trip. The companion page self-host fmt covers the format half of the pipeline; this one closes the loop.
Source:
eval.mere
(tree-walking interpreter),
parser.mere,
lexer.mere,
bridged by
selfhost-repl.mere.
The shared AST lives in
contrib/parser/ast.mere.
(press Run to evaluate)
Pipeline
Four contrib libraries combine into the Wasm running on this page:
lexer.mere— source → tokensparser.mere— tokens → ASTeval.mere— AST → value (this stage)selfhost-repl.mere— DOM glue (textarea →parse_and_eval→ output)
eval.mere covers literals, the binary / comparison /
logical operator groups, if, closures with captured
env, let and match with the full
pattern set, let rec with mutual recursion via the
VRecBinding placeholder trick (pure-functional, no
ref), constructors, tuples, lists (with
[1, 2, 3] reconstruction over Cons /
Nil), and records (literal / field access / update /
pattern match). The host-provided builtin set is currently just
print and show — most useful work
flows through the operator-level paths instead.
Limitations
-
Errors abort the Wasm instance. If your input
triggers a parse error, unbound variable, or pattern mismatch,
the message goes to print output and the Wasm traps;
reload the page to recover. (The OCaml side uses exceptions
for this; the self-host stays simple and uses
failwhich aborts.) -
Builtin set is minimal. Only
printandshoware wired through as host functions. Multi-arg builtins (str_concat,list_map, …) need partial application machinery onVBuiltin— a follow-up slice. Most expressions flow throughEBin/ECmp/EAppwith user-defined closures, so this constrains less than it sounds. - No types. The evaluator runs untyped. Type annotations parse fine and are ignored at eval time; type decls register no runtime info. A self-host typer is §S2 Phase 52, still on paper.
Why this matters
Phase 51 closes §S2.A — the self-host evaluator. Combined with §S1 (self-host parser + fmt, Phase 49 + 50), Mere can now parse, format, AND evaluate its own source code, in the browser, with no server round-trip.