Scheme has a number of well-defined types; unfortunately, those types do not map exactly on the Python types. In order to return meaningful results from the eval method, Psyche wraps some of those types in Python objects. These objects can be found in the psyche.types module.
Table 5.1 shows how Scheme types are mapped on Python types and Psyche objects.
Scheme supports the notion of symbols, something that does not exist in Python. Therefore, Psyche provides the class Symbol that models Scheme symbols.
There are two kinds of symbols in Scheme:
Every symbol also has a string representation, which can be obtained by symbol->string. Two symbols are identical if and only if they have an identical string representation.
The string representation differs between literal symbols and symbols created by string->symbol: the former are always represented in lower case5.1, while the latter are represented exactly like the string they were derived from.
The Psyche class Symbol implements this by providing a constructor with two arguments: name and the optional fromString. Two symbols are equal iff
Since symbols occur frequently in Scheme programs, literal Symbols are interned using the Flyweight pattern. The Flyweight pool uses weak references, assuring that Symbols are garbage collected as soon as there are no other references left.
The result of this is that the eqv? on literals is identical to using the Python is comparison keyword.
In Scheme, there are three kinds of strings:
String literals are immutable and are represented by the Python type str.
Strings returned symbol->string are immutable as well; however, they have the added functionality that calling string->symbol on such a string returns an interned symbol (see 5.1 for more information on such symbols). Strings returned by symbol->string are represented by the Psyche class SymbolString, a subclass of str.
SymbolStrings are identical to str in all respects, apart from an extra field used by the string->symbol function.
All other strings in Scheme are mutable. They are represented by the Psyche class MString, also a subclass of str. MStrings behave exactly like str, with the added functionality of supporting __setitem__.
MString.__setitem__ only accepts single character strings. All other values raise a TypeError.
Scheme has pairs as a built-in datatype. Pairs are used to implement lists, by setting the cdr of a pair to another pair or the empty list.