1. Getting started
Install
-
Open the latest release and download the file for your system:
System File Windows elomar-<version>-x86_64-pc-windows-msvc.zipLinux elomar-<version>-x86_64-unknown-linux-gnu.tar.gzmacOS (Apple chips) elomar-<version>-aarch64-apple-darwin.tar.gzmacOS (Intel) elomar-<version>-x86_64-apple-darwin.tar.gz - Unpack it and put
elomar(elomar.exeon Windows) in a folder on yourPATH. On macOS, the first run may needxattr -d com.apple.quarantine elomar. -
Check it works:
elomar --version
Your first program
Create a file named hello.elo:
fn main() {
print("Hello, world!")
print("مرحبًا بالعالم!")
}
Run it:
elomar run hello.elo
Every program starts at fn main(). print writes its values and a line
break.
Try things at the prompt
elomar repl opens a prompt: type a line and see its result at once,
without making a file. It is the quickest way to try an idea:
elomar repl
> 2 + 3 * 4
14
> let name = "Lina"
> "Hello, {name}!"
"Hello, Lina!"
> [3, 1, 2].sorted()
[1, 2, 3]
Variables and functions you type stay for the next lines. :help lists
the commands and :quit leaves.
Talking to the user
input shows a prompt and returns what the user typed:
fn main() {
let name = input("What is your name? ")
print("Nice to meet you, {name}!")
}
The {name} inside the text is replaced by the value of name. This is
called string interpolation; you can put any expression between the
braces.
When something is wrong
Elomar-Lang checks your whole program before running it. Try this:
fn main() {
let age = 30
print(age + "years")
}
error[E2005]: operator `+` cannot be applied to `Int` and `String`
Nothing ran: the mistake was found first. Add --lang ar to see messages
in Arabic: elomar --lang ar run hello.elo.
The editor
In VS Code, VSCodium, Cursor and other editors, search for Elomar-Lang in the Extensions view and install it. You get colors, errors while you type, hover information, completion and a Run button.
To find a mistake, click left of a line number to set a breakpoint (a red dot) and press F5. The program stops there: you see the value of every variable, and can go on one line at a time (F10), step into a function (F11) or continue (F5). If the program fails, it stops on the failing line so you can see why.
Commands you will use
| Command | What it does |
|---|---|
elomar run file.elo |
Check and run a program |
elomar repl |
Type code and see the result at once |
elomar check file.elo |
Only check for errors |
elomar build file.elo |
Make an executable to share |
elomar fmt file.elo |
Format the code in the standard style |
elomar new myapp |
Create a project with tests |
elomar test |
Run a project’s tests |
Exercises
Write your answer and press Check: it is tested in your browser on several cases. Your work is saved on this device.