Skip to main content

Week 5 Studio: The goto field

Turning Movement I's evaluator into a statement executor — the goto field, failure propagation, and a couple of predicates to branch on

22 March 2027

Before the session

Bring week 4’s working evaluator: lexer, parser, symbol table, and a tree-walking evaluator for literals, arithmetic, variables, and concatenation. This session wraps it in something new rather than replacing any of it — the expression evaluator you already have becomes the thing each statement’s subject and object are evaluated with.

In the session

Sample transcript

Genuine captured output from this course’s own week-5 reference statement executor, run against a counting loop built entirely from assignment, a predicate, and the goto field:

$ dune exec bin/main.exe -- examples/count.sno
1
2
3
4
5
DONE

The stopping point is worth tracing by hand: the loop increments and checks LE(N,5) after printing, so it prints 5 once more before the predicate finally fails and falls through to DONE — an off-by-one error in either direction would show up as 4 or 6 still appearing above DONE, not as a crash.

This week’s real starter — the goto-field dispatch and the six predicates stubbed out — is downloadable at week-05-starter.zip.

Afterwards

The statement executor and goto-field dispatch you build this week is what next week’s function calls sit on top of: a DEFINEd function call is, to the caller, just another statement that succeeds or fails, dispatched by the same goto-field machinery rather than a separate calling mechanism. Keep the predicate implementations too — they’re the easiest way to give a recursive function something to test against before the pattern engine arrives.

The spec

What you bring to the session. Written so a reader can tell whether it has been met without asking you.

Teaching team