Interpreter test
There are a number of small interpreter tests throughout the documentation; this is a bit longer piece of code that generates a simple times table.
fun pad(n: Int): Str {
let s = int-to-str(n);
return n lt 10 ? { true -> " " ++ s; false -> s };
}
do {
let mut c = 1;
let mut title = " |"
while c lt 10 {
title ++= " ";
title ++= pad(c);
c += 1;
}
print-line(title);
print-line("-------------------------------");
let mut r = 1;
while r lt 10 {
let mut c = 1;
let mut line = pad(r) ++ " |";
while c lt 10 {
line ++= " ";
line ++= pad(c * r);
c += 1;
}
print-line(line);
r += 1;
}
}
This example tests our web implementation of the read-line builtin.
do {
let mut i = 0;
print-line("Type some stuff in the input below!");
while i lt 5 {
let line = read-line();
if line eq #eof {
break
}
print-line("You typed: " ++ line ! line);
i += 1
}
print-line("Okay, that's enough.")
}