The aime "Hello, World!" program is:
o_text("Hello, World!\n");
‘o_text’ is a function, outputting a piece of text (a string). It expects one argument, of the intrinsic string type. ‘"Hello, World!\n"’ is a string literal (a string constant). aime string literals are surrounded by double quotes. The final ‘\n’ character of the string is the newline. The ‘;’ makes the preceding expression a statement (an instruction), i.e. it tells the aime interpreter to evaluate (execute) it.
The program displays Hello, World!.
Counting to 10 is:
integer i; i = 1; while (i <= 10) { o_integer(i); o_newline(); i = i + 1; }
‘integer i;’ is a variable declaration, it declares ‘i’ of type ‘integer’. ‘i = 1;’ sets ‘i’ as 1. ‘while (i <= 10)’ will loops through the block that follows for as long as ‘i’ is equal or less than 10. Blocks are compound statements marked by braces. ‘o_integer(i);’ displays ‘i’ while ‘o_newline();’ outputs a newline character (moves to a new line). ‘i = i + 1;’ increments ‘i’ by 1.
The program will display the numbers 1 through 10, one per line.
aime programs may be procedural. When they are, all the statements and variable declarations belong to a function (a procedure). Functions are callable blocks that describe an input set, an output (or return) type and have a callable name. The function called ‘main’ with no input (parameters) and returning an ‘integer’ value is called (evaluated) when the program is executed.
The simplest aime procedural program does nothing:
integer main(void) { return 0; }
The simplest aime non procedural program is the empty program.
integer factorial(integer n) { integer i, result; result = 1; i = 1; while (i < n) { i = i + 1; result = result * i; } return result; } integer main(void) { o_integer(factorial(8)); o_newline(); o_integer(factorial(10)); o_newline(); return 0; }
The program displays the factorial of 8 and 10 (the factorial of a positive integer n is defined as the product of the sequence n, n - 1, n - 2, ... 1).
The function ‘factorial’ computes and returns an ‘integer’ value. It expect exactly one argument, of the same ‘integer’ type. ‘i’ and ‘result’ are two ‘integer’ variables, set both to 1. The function loops for as long as ‘i’ is less than the input ‘n’, incrementing ‘i’ and multiplying ‘result’ with ‘i’ at each step. The final statement makes ‘result’ the computed value of ‘factorial’.
Each function has exactly one ‘return’ statement and the ‘return’ statement is always the last one, except for functions that return no value and that feature no ‘return’ statements. The type of the expression following the ‘return’ keyword must match the return type of the function.
void out(text s) { o_text(s); o_space(1); o_integer(length(s)); o_newline(); } integer main(void) { out("xoxo"); out("ennui"); out("in the shadow"); return 0; }
The ‘out’ function displays its input string and the length of it, with a white space in between and moving to the next line. The output of the program is:
xoxo 4 ennui 5 in the shadow 13
‘out’ evaluates to (returns) no value when called, hence the ‘void’ for its return type.
It may be rewritten to a more compact form as:
void out(text s) { o_(s, " ", length(s), "\n"); }
or to a C-ish form as:
void out(text s) { o_form("%s %d\n", s, length(s)); }