REPL
Start it with:
bash
legion repllhj
legionhjyu 1.0.0
Type :help for commands, :exit to quit
>>>Basic usage
Type any legionhjyu expression or statement and press Enter:
lhj
>>> forge x = 42
>>> echo x
42
>>> x * 2
84
>>> "hello" + " world"
hello worldThe last result is stored in _:
lhj
>>> 3 + 4
7
>>> _ * 10
70Multi-line input
The REPL detects when you're in the middle of a block (a blade, march, ritual, etc.) and waits for more input. Indent with spaces:
lhj
>>> blade square(n):
... release n * n
...
>>> square(9)
81Press Enter on a blank line to finish a block.
REPL commands
These start with : and run immediately:
| Command | What it does |
|---|---|
:help | Print all REPL commands |
:exit | Quit the REPL |
:quit | Same as :exit |
:clear | Clear the screen |
:env | Print all variables in the current scope |
:reset | Clear all variables and start a fresh scope |
:load | Load and execute a .lhj file |
:time | Run an expression and print how long it took |
:ast | Print the AST for an expression |
:tokens | Print the token stream for an expression |
Examples:
lhj
>>> :env
x = 42
>>> :time sorted([5,3,1,4,2])
0.0001s → [1, 2, 3, 4, 5]
>>> :ast 1 + 2
BinOp(op=+, left=IntLit(1), right=IntLit(2))
>>> :load ./utils.lhj
Loaded utils.lhjHistory
The REPL saves history to ~/.legion/repl_history. Press the up arrow to cycle through previous entries.
Tips
You can define functions and classes in the REPL the same way you would in a file. They persist until you :reset or quit:
lhj
>>> ritual Point:
... blade awaken(self, x, y):
... self.x = x
... self.y = y
...
>>> forge p = Point(3, 4)
>>> echo p.x
3Use :load to bring in utility functions from a file without leaving the REPL:
lhj
>>> :load ./my_helpers.lhj
>>> my_function(42)