@head @module std @title std: Basic services
This module defines several basic types, constants and utility functions. The types include the primitive types, basic collection types and several exception types. The std module is the only module that is always imported without an explicit import definition, and its services are used by practically every Alore program.
The main purpose of the hash value is to spread different objects in different slots of a hash table most of the time, and to collect equal objects in the same slots. Therefore, even though technically all objects of a certain type could have the same hash value, this would result in a dramatic slowdown of certain operations. Due to efficiency reasons, the optimal maximum magnitude of hash values is typically about 2**29. @end @fun Exit([value as Int]) @desc Exit the program. The optional argument specifies an integer return value to the operating system. The function is implemented by raising an ExitException. It can be caught using a try statement to prevent the program from exiting. @end
This module also defines boolean constants: @var True @desc The boolean true value. @end @var False @desc The boolean false value. @end
A few string constants are provided as well: @var Tab @desc The tab character (code 9). @end @var Newline @desc The platform specific line break string. On Unix-like operating systems it is LF and on Windows CR + LF. @end @var LF @desc The line feed character (code 10). @end @var CR @desc The carriage return character (code 13). @end
The exception classes in the std module form this inheritance hierarchy:
These exception classes have similar functionality inherited from Exception: @class Exception([message as Str]) @desc The base class of all exceptions. Exception has a single member, message, that contains the error message argument given to the constructor, or nil if the message argument was omitted or if it was nil. @end @class ValueError([message as Str]) @desc Raised when the input values of an operation or a function have invalid types or values. Typically, ValueError signifies a programming error, but it can be caught to recover from these situations. The several subclasses of ValueError indicate more specific conditions. @end @class TypeError([message as Str]) @desc Raised when the inputs of an operation or a function have unsupported types. Note that MemberError will be often raised in similar situations. @end @class MemberError([message as Str]) @desc Raised when an object does not have a requested member or the member being assigned to cannot be modified. @end @class ArithmeticError([message as Str]) @desc Raised when an arithmetic operation or function receives invalid inputs. A typical example is division by zero. @end @class IndexError([message as Str]) @desc Raised when the index of a sequence object such as an array is out of bounds or otherwise invalid. @end @class KeyError([message as Str]) @desc Raised when a key of a mapping object is not present or is otherwise invalid. @end @class CastError([message as Str]) @desc Raised when a cast operation fails. @end @class ResourceError([message as Str]) @desc Raised when a resource is exhausted. This exception can be triggered by lack of disk space or by too many open files, for example. @end @class MemoryError([message as Str]) @desc Raised when a memory allocation request cannot be fulfilled. This exception may also be raised if only a specific kind of memory pool is exhausted, even though there might be memory available for other purposes. @end @class RuntimeError([message as Str]) @desc Raised when there is a run-time error during execution that does not have a more specific exception class. @end @class InterruptException([message as Str]) @desc Raised when the user interrupts the program by pressing Ctrl+C. @end
IoError also has the following member constants: @var code as Constant @desc The symbolic constant representing the error. If an integer value was passed to the constructor, IoError tries to map the integer to a symbolic constant using the @ref{errno} module; failing that, or if the error argument was not present, the value is nil. @end @var errno as Int @desc The integer errno value representing the error. If a symbolic constant was passed to the constructor, IoError tries to map the constant to an integer value using the @ref{errno} module; failing that, or if the error argument was not present, the value is 0. @end @end-class