Our language is imperative with each statement terminated with a semi-colon ;
. Arguments passed to functions are separated by spaces similar to functional languages such as Ocaml/Scheme.
Below is a simple example program which takes an integer input from stdin and prints to stdout:
int value = console.read_int;
console.print_int value;
Curly brackets { }
are used to denote scope in loops, conditionals and lambda expressions.
Variables are used to store dynamic values, with assignment syntax similar to most programming languages:
int variable = 0;
The value of 'variable' is now the integer 0.
All basic arithmetic operations are supported:
int + int
orint math.plus int
- additionint - int
orint math.minus int
- subtractionint * int
orint math.mul int
- multiplicationint / int
orint math.div int
- divisionint % int
orint math.mod int
- modulusint ^ int
orint math.pow int
- power/index
math.sqrt <int>
- square root functionmath.log <int>
- logarithm functionmath.fact <int>
- factorial functionmath.sign <int>
- integer sign function (returns +1/-1)math.max <int> <int>
- bigger number functionmath.min <int> <int>
- smaller number function
All I/O operations interact with stdin/stdout and all built in functions are part of console
similar to JavaScript.
console.read_int
- read an integer from stdinconsole.read_string
- read a string from stdinconsole.read_bool
- read a boolean from stdin
-
console.print_int
- print an integer to stdout -
console.print_string
- print a string to stdout -
console.print_bool
- print a boolean to stdout -
console.println_int
- print an integer to stdout with new line terminator -
console.println_string
- print a string to stdout with new line terminator -
console.println_bool
- print a boolean to stdout with new line terminator
-
console.error_int
- print an error to stdout as an integer -
console.error_string
- print an error to stdout as a string -
console.error_bool
- print an error to stdout as a boolean -
console.errorln_int
- print an error to stdout as an integer with new line terminator -
console.errorln_string
- print an error to stdout as a string with new line terminator -
console.errorln_bool
- print an error to stdout as a boolean with new line terminator
Loops are important when operating on streams of continuous data. For this reason, loops are simple in our language:
loop {
console.println_int console.read_int;
}
The above program will loop printing integers from stdin to stdout with a new line terminator. The loop will continue until EOF
is encountered.
It is also possible to loop based on any boolean condition in a while/do or do/while loop.
While/do
while (someValue < someOtherValue) do {
console.println_string "Hello world!";
}
Do/while
do {
console.println_string "Hello world!";
} while (someValue < someOtherValue);
Hello world!
will be printed to stdout for as long as someValue < someOtherValue
evaluates to true.
A do/while will always execute at least once even if someValue < someOtherValue
always evaluates to false. Contrastingly, a while/do will not print to stdout if someValue < someOtherValue
is never true.