Module prelude

The prelude module provides the classes, vars, and functions that form the foundation of Lily.

Classes

Boolean The Boolean class represents a value that is either true or false.
Byte The Byte class represents a wrapper over a single Byte value. A Byte value is always unsigned, giving it a range from 0 to 255. Byte literals are written using 't' as the suffix on an Integer value.
ByteString The ByteString class represents a bag of bytes. A ByteString may have '\0' values embedded within it. It may also have data that is not valid as utf-8. The ByteString class currently does not support any primitive operations.
Double The Double class exists as a wrapper over a C double.
File The File class provides a wrapper over a C FILE * struct. A File is closed automatically when a scope exits (though not immediately). However, it is also possible to manually close a File.
Function The Function class represents a block of code to be called, which may or may not produce a value. Function values are first-class, and can be passed around as arguments, placed into a List, and so on.
Hash The Hash class provides a mapping between a key and a value. Hash values can be created through [key1 => value1, key2 => value2, ...]. When writing a Hash, the key is the first type, and the value is the second.
Integer The Integer class is Lily's native numeric type. Internally, it is a wrapper over a C int64_t.
List The List class represents a container of a given type, written as List[<inner type>]. A List value can be accessed through a positive index or a negative one (with negative indexes being an offset from the end). Attempting to access an invalid index will produce IndexError.
String The String class provides a wrapper over a C char *. The String class is guaranteed to have a single '\0' terminator. Additionally, a String is guaranteed to always be valid utf-8.
Tuple The Tuple class provides a fixed-size container over a set of types. Tuple is ideal for situations where a variety of data is needed, but a class is too complex.
Unit

Enums

Option The Option type presents a way to hold either a value of A, or None, with None being valid for any Option. A common use for this is as a return type for functions that may fail, but have no meaningful error message.
Result Result is an enum that holds either a Failure or Success. This enum is for situations where the function that fails has an error message to deliver. Examples of that include a database query or a more humble rpn calculator.

Exceptions

DivisionByZeroError The DivisionByZeroError is a subclass of Exception that is raised when trying to divide or modulo by zero.
Exception The Exception class is the base class of all exceptions. It defines two properties: A message as String, and a traceback as List[String]. The traceback field is rewritten whenever an exception instance is raised.
IOError IOError is a subclass of Exception that is raised when an IO operation fails or does not have permission.
IndexError IndexError is a subclass of Exception that is raised when attempting to access an index that is out-of-bounds (too low or too high, after accounting for negative wraparound).
KeyError KeyError is a subclass of Exception that is raised when trying to get an item from a Hash that does not exist.
RuntimeError RuntimeError is a subclass of Exception that is raised when the recursion limit is exceeded, or when trying to modify a Hash while iterating over it.
ValueError ValueError is a subclass of Exception that is raised when sending an improper argument to a function, such as trying to call List.repeat with a negative amount.

Functions

define calltrace: List[String]

Returns a List with one String for each function that is currently entered.

define print(value: A)

Write value to stdout, plus a newline ("\n"). This is equivalent to stdout.print(value).

Vars

var stderr: File

Provides a wrapper around the stderr present within C.

var stdin: File

Provides a wrapper around the stdin present within C.

var stdout: File

Provides a wrapper around the stdout present within C.