Skip to main content

Week 9 Studio: Getting something back from a match

Wiring conditional and immediate assignment, @X, and the enumerate-all-matches idiom into last week's matcher

19 April 2027

Before the session

Bring last week’s matcher with all seven primitives from Movement III’s vocabulary working correctly under the three-condition cursor contract. This session doesn’t add new matching primitives; it adds a way to get information back out of a match that already succeeds.

In the session

Sample transcript

Genuine captured output from this course’s own checkpoint-3 reference solution — the fullest transcript of the three checkpoints, since it is the first one exercising conditional assignment and backtracking together:

$ dune exec bin/main.exe -- examples/bind_replace.sno
HELLO SNOBOL4
HELLO, ALICE!
CORRECTLY FAILED, LINE2 UNCHANGED = NAME: BOB

$ dune exec bin/main.exe -- examples/primitives.sno
LEN(5) MATCHED ALL OF HELLO
LEN(6) CORRECTLY FAILED (ONLY 5 CHARS)
SPAN CAPTURED LEADING WHITESPACE: [   ]
NOTANY CORRECTLY FAILED ON AN ALL-DIGIT SUBJECT
LETTERS=ABC DIGITS=123
ARB CAPTURED VAL=42

bind_replace.sno’s third line is the one to check by hand before the session: a conditional assignment inside a match that goes on to fail overall must leave LINE2 exactly as it was, not holding a stale capture from the attempt that failed — the same undo discipline this session’s first studio task asks you to build and test directly.

Afterwards

Movement III is complete: patterns as values, a correctly-backtracking matcher over seven primitives, and both ways of getting information back out of a match. Checkpoint 3, due at the end of this week, asks you to bring all three weeks together against a fuller sample transcript than any single session has exercised alone.

The spec

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

Teaching team