Skip to content

Session 4 — REPL & Interactive Prompt

What Was Built

The REPL (Read, Evaluate, Print, Loop) — an interactive prompt that lets you write Terse code one line at a time and see results instantly. The moment Terse became a language you can have a conversation with.


The REPL

File: src/interpreter/main.py

Run with no arguments to start the interactive prompt:

python main.py
Terse 0.1 — Goatface Tech
Type "exit" to quit, "clear" to reset knowledge base.

>>>

How It Works

The REPL creates a single Interpreter instance and keeps it alive for the whole session. Every line you type gets run through the full Lexer → Parser → Interpreter pipeline. The knowledge base accumulates across lines — everything you teach Terse stays in memory until you exit or clear.

Terse 0.1 — Goatface Tech
Type "exit" to quit, "clear" to reset knowledge base.

>>> know dog is animal
  learned: dog is animal

>>> know dog has fur
  learned: dog has fur

>>> when has fur then is mammal
  rule learned: when has fur then is mammal

>>> infer dog
  inferring: dog
  inferred: dog is mammal

>>> facts
  dog: {'is': 'mammal', 'has': 'fur'}

>>> exit
Goodbye.

Special Commands

The REPL has five built-in commands beyond standard Terse syntax:

Command What it does
exit Quit the REPL cleanly
clear Reset the knowledge base — fresh interpreter
facts Print all known node facts
relationships Print all known edges between nodes
sequences Print all Markov chain transitions with probabilities

These give you full visibility into what Terse knows at any point in a session.


Running Files vs REPL

main.py now serves two purposes:

# Start the REPL
python main.py

# Run a .trs file
python main.py ../../examples/hello.trs

If you pass a filename it runs that file. If you pass nothing it starts the interactive prompt.


Why the REPL Matters

Before the REPL, Terse was a file runner. You wrote code, saved it, ran it, read the output. The REPL changes that — you can explore the knowledge base interactively, test inference rules live, and teach Terse things one line at a time.

It also makes Terse approachable. Anyone can type know dog is animal and immediately see learned: dog is animal. No setup, no files, no compilation. Just a conversation.


Phase 1 Progress After Session 4

Component Status
Lexer ✅ Complete
Parser ✅ Complete
Interpreter core ✅ Complete
Facts & relationships ✅ Complete
Inference rules ✅ Complete
Functions with scope ✅ Complete
Markov chain learning ✅ Complete
Each loops ✅ Complete
While loops ✅ Complete
main.py ✅ Complete
First .trs program ✅ Complete
REPL ✅ Complete
Error handling 🔵 Next session
Tensors ⚪ Planned
Compression keywords ⚪ Planned
Ethics rule syntax ⚪ Planned

Interpreter completeness: ~75%