Language Guide: Page 4
A crash course in the particular workings of microscheme
Type System
Microscheme has a strong dynamic type system. It is strong in the sense that:
- All values have a specific, definite type
- No type coersion occurs
- Procedures are generally valid for a specific set of types
- Type exceptions are raised when procedures are applied to values of the wrong type
It is dynamic in the sense that a variable is not restricted to hold values of a certain type. The type of value to which a variable name will be bound is not known until runtime, and can change as the program progresses.
The built-in types are: Number, Char, Boolean, Pair, Vector, ‘The Empty List’ aka null, which is said to have a type of its own, and Procedure. From these basic types we can infer compound types. A List is defined to be something of the type null or pair where the value of the cdr field has type List. This definition is effectively implemented by the (list? …) function in the ‘list.ms’ library.
Even though the built-in numeric type is fairly restricted (15-bit unsigned integer), a richer numeric stack can be built using combinations of pairs, vectors and numbers. For example, the 'xtypes.ms' library provides types long and fp, which represent 8-digit unsigned integers, and 4+4 digit fixed-point real numbers respectively.
For every type, there is a predicate function which answers the question 'is this value of type X'. These predicates are consistently formed by appending a question mark to the type name. For example, (number? 4) evaluates to #t. (boolean? 4) evaluates to #f. (boolean? (number? 4)) evaluates to #t.
Procedures for converting between types are formed with an arrow between the type names, e.g. (vector->list a b). These conversions are not provided for many types, but they can be written manually.