REPL

Start it with:

bash
legion repl
lhj
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 world

The last result is stored in _:

lhj
>>> 3 + 4
7
>>> _ * 10
70

Multi-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)
81

Press Enter on a blank line to finish a block.

REPL commands

These start with : and run immediately:

CommandWhat it does
:helpPrint all REPL commands
:exitQuit the REPL
:quitSame as :exit
:clearClear the screen
:envPrint all variables in the current scope
:resetClear 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.lhj

History

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
3

Use :load to bring in utility functions from a file without leaving the REPL:

lhj
>>> :load ./my_helpers.lhj
>>> my_function(42)