The Amalthea Environment

The Types

Amalthea has three different kinds of continuations, string continuations, integer continuations, and expression continuations. Only expression continuations can be invoked. Integer continuations and string continuations are still called continuations as they could be made invokable (i.e. expressed as continuations proper) but they are in fact primitive for convinience and performance reasons. This means they can only be expressed as literals or examined and created by primitive standard environment continuations. I.e. you can't call an integer continuation, which is the only way to examine a continuation, but have to use for example '+' to calculate a new continuation from it and another integer continuation. The literals looks like in most languages:

String continuations: "string"

Integer continuations: 42

The standard environment

Amalthea's standard environment contains a number of functions for examining and constructing string and integer continuations, and also the unique continuation terminate. Applying a primitive continuation to different continuation types than it was inteded for will result in an error message and program termination.

terminate - Accepts no parameters and does nothing, resulting in program termination.

+ intA intB (-> intR) - Accepts three parameters, the first ones are integer continuations and the last parameter is applied to the result from adding these two.

- intA intB (-> intR) - Same as + except it subtracts instead.

* intA intB (-> intR) - Same as + except it multiples instead.

/ intA intB (-> intR) - Same as + except it divides instead. Division by zero terminates the program with an error message.

= A B contT contF - Calls contT if A and B are equal ints or strings, otherwise contF.

< intA intB contT contF - Calls contT if intA is less than intB, otherwise contF.

> intA intB contT contF - Calls contT if intA is greater than intB, otherwise contF.

^ strA strB (-> strR) - Calls it's last argument with strA and strB concatenated.

substr strA intF intL (-> strR) - Calls it's last argument with the substring from strA specified by the first char intF and the last char intL, exclusive intL.

string_length strA (-> intR) - Calls it's last argument with the integer length of strA.

string_of_int intA (-> strR) - Calls it's last argument with the string representation of intA.

int_of_string strA (-> intR) - Calls it's last argument with the integer represented by strA. If strA doesn't represent a valid integer the program terminates with an error.

print_int intA contA - Prints it's first argument on standard out followed by a newline, then calls it's second argument.

print_int intA contA - Prints it's first argument on standard out followed by a newline, then calls it's second argument.

print_int_ strA contA - Prints it's first argument on standard out, then calls it's second argument.

print_string_ strA contA - Prints it's first argument on standard out, then calls it's second argument.

Standard library and examples

Eventually Amalthea is meant to be distributed with a more complete standard library, but for now I decided I didn't have time to finish it all up as it needs to be designed as well. For now there're a few functions for handling lists, tuples, and iterators. Iterators are probably the most interesting as it's a standard interface to any collection object so they can be iterated over. List are iterators to begin with, you can construct an iterator over a tuple, and an example is included where an in-order iterator is constructed over a sorted binary tree. Any iterator can be used with the map, for_each, and combine functions. Of these map and combine in turn produce iterators of themselves and so can be used over infinite iterators (such as iterators constructed by Range, also included in the iterator module).

Look around in the modules to find out what's included.