Hera is a simple programming language made to learn more about interpreters and compilers.
# To run a .hera file
hera run <filename>.hera
# To open the REPL
hera
All declaration statements should end with a
;
!
let name = value;
# strings
let a = "hi";
# boolean
let b = true;
# integer
let c = 10;
update name = value;
let a = 10;
update a = 15;
# declaration
let arr = [1,2,3,4];
# Accessing elements
arr[0] # --> 1
arr[1] # --> 2
arr[-1] # --> 4
let hash = {
"one": "Hello",
"two": "World!",
3: "number as key",
3+4: "my key is 7",
true: "my key is a boolean"
};
hash["one"] # "Hello"
hash[3] # "number as key"
hash[7] # "my key is 7"
hash[true] # "my key is boolean"
let name = fn(<params>) {
<body>
};
let double = fn(x) {
x * 2
};
double(10) # 20
You can directly put the expression or value to return without any keyword or semicolon or use return x * 2;
if (<condition>) {
<body>
}
else {
<body>
}
else if (<condition>) {
<body>
}
if (3 > 4) {
print("wtf");
} else if (4 > 3) {
print("correct lol");
} else {
print("idk man");
}
The only library currently available is std
import <lib>;
import std;
print(argument)
- Prints the argument on the screen
push(array, value)
- Inserts a value in an array
tail(array)
- Returns a new array without the first element of the given array
len(argument)
- Returns the length of a string or an array
map(array, function)
- Runs the function on all elements of the given array and returns a new array with the returned values from the function
Example:
let array = [2,3,4,5];
let double = fn(x) {
x \* 2
};
let new = map(array, double);
# new = [4,6,8,10]
while(condition, body)
- A while loop that runs the body till the condition is true
Example:
let i = 1;
let condition = fn() { i < 15 };
while(condition, fn() {
print(i);
update i = i+1;
});
range(limit)
- Returns an array with numbers from 1 to limit
abs(num)
- Returns a positive variant of the given negative or postive number
first(array)
- Returns the first element of an array
last(array)
- Returns the last element of an array