The Standard Prelude

Introduction

The prelude is the Io module that is automatically imported into all other Io programs and source files. It's normally located in the standard library and is imported just like any module, with the library paths searched as usual. The standard prelude is the prelude included with the Amalthea distribution and it's mostly a front end for a number of other modules in the standard library which it exports in their entierty or only partly. If the prelude isn't imported no predeclared continuations att all will be available to a program in an empty file.

One can force Amalthea not to load the prelude module by invoking the interpreter with the switch -noprelude. This prevents the prelude from being imported automatically both into the main program and into any modules it depends on, unless it's explicitly imported.

Continuations Exported from the Prelude

From the Prelude itself
NameArgumentsDescription
terminate Accepts no parameters and does nothing, resulting in program termination.
=A B contT contF Calls contT if A and B are equal ints or strings, otherwise contF.

 
From the Int module
NameArgumentsDescription
+intA intB -> intR Adds integer arguments A and B and calls the last argument with the result.
-intA intB -> intR Subtracts integer arguments B from A and calls the last argument with the result.
*intA intB -> intR Multiplies integer arguments A and B and calls the last argument with the result.
/intA intB -> intR Divides integer arguments A by B and calls the last argument with the result. Division by zero terminates the program with an error message.
<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.
print_intint cont Prints the integer argument on standard out followed by a newline, then calls the second argument.
print_int_int cont Prints the integer argument on standard out and calls the second argument.
string_of_intint -> str Calls the second argument with the integer argument represented as a string.

 
From the String module
NameArgumentsDescription
^strA strB -> strR Concatenates the strings strA and strB, calls the last argument continuation with the result..
=A B contT contF Calls contT if A and B are equal ints or strings, 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.