Quick start
This page walks through three short programs that cover the most common parts of the language. If you want to read the full syntax reference first, start with Variables.
Your first file
Create hello.lhj:
lhj
forge name = "Legionnaire"
echo "Hello, {name}!"
echo "The language is: legionhjyu"Run it:
bash
legion run hello.lhjlhj
Hello, Legionnaire!
The language is: legionhjyuA function
lhj
## greet.lhj
blade greet(name: str, loud: yep = nope) -> str:
forge msg = "Hello, {name}!"
blade loud:
release shout(msg)
release msg
echo greet("Aria") ## Hello, Aria!
echo greet("Rex", yep) ## HELLO, REX!blade defines a function. yep and nope are the boolean literals. release returns a value. blade used as an if check on the next line — that's the pattern-match form.
A class
lhj
## warrior.lhj
ritual Warrior:
blade awaken(self, name: str, hp: int = 100):
self.name = name
self.hp = hp
blade attack(self, target):
target.hp <- target.hp - 20
echo "{self.name} hits {target.name} for 20 damage"
blade alive(self):
release self.hp > 0
forge hero = Warrior("Aria")
forge enemy = Warrior("Shadow", 60)
march hero.alive() and enemy.alive():
hero.attack(enemy)
blade enemy.alive():
enemy.attack(hero)
echo "Battle over!"
echo "Aria HP: {hero.hp}"
echo "Shadow HP: {enemy.hp}"ritual defines a class. awaken is the constructor. march runs a loop while the condition holds. blade ... : is the if statement.
Pipelines
lhj
## pipeline.lhj
forge numbers = [3, 1, 4, 1, 5, 9, 2, 6]
forge result = numbers
|> sorted
|> reversed
march item in result:
echo itemThe |> pipe passes the left side as the first argument to the right side. Chaining works across lines when continued at the |>.
The REPL
If you want to explore without writing files, start the REPL:
bash
legion repllhj
legionhjyu 1.0.0
Type :help for commands, :exit to quit
>>> forge x = 10
>>> forge y = 20
>>> echo x + y
30
>>> :env
x = 10
y = 20
>>> :exit