Basics
Comments
Aspen uses C style comments.
// this is a line comment
/*
this block comment
can span multiple lines
*/
Printing
All output in Aspen is done through the print statement.
print "Hello, world!";
There is no way to read input in an Aspen program.
Variables
Variables are declared with the let keyword.
let n i64;
let foo string;
Aspen is statically typed, every variable must be annotated with a type. In the example above, n is a variable of type i64, a 64 bit integer and foo has type string.
There is no type inference in Aspen, every variable must be declared with a type.
All variables must be declared with a type
let name = "Arun Muthu";
name has been annotated with the type string
let name string = "Arun Muthu";
Reserved Keywords
Here is the list of keywords reserved by Aspen.
else for fn void if print return true false let while i64 u64 bool string double
Blocks
Similar to how parenthesis group multiple expressions into one big expression, a block groups multiple statements into one big statement. A block creates a local scope, variables declared inside a block will only be visible inside the block.
{
let greeting string = "こんにちは";
print greeting;
}
let welcome string = greeting + " Jordan."; // error, greeting is out of scope
Blocks always appear after an if, while or for statement.
if (12*12 > 100) {
print "12*12 is greater than 100.";
}
Operators
| Precedence | Operator | Description | Associates |
|---|---|---|---|
| 1 | fn() () type() | Function call, Grouping, Type cast | Left |
| 2 | ! - | Not, Negation | Right |
| 3 | / * % | Divide, Multiply, Modulus | Left |
| 4 | + - | Add, Subtract | Left |
| 5 | & | Bitwise and | Left |
| 6 | ^ | Bitwise xor | Left |
| 7 | | | Bitwise or | Left |
| 8 | > >= < <= | Comparison | Left |
| 9 | == != | Equals, Not equal | Left |
| 10 | && | Logic and | Left |
| 11 | || | Logic or | Left |
| 12 | = | Assignment | Right |