Conversion

The defined name of this module is convert.

The mechanism for the conversion of an instance of one class to an instance of another is defined by a user-extensible framework which has some similarity to the setter mechanism.

To the user, the interface to conversion is via the function convert, which takes an object and some class to which the object is to be converted. The target class is used to access an associated converter function, in fact, a generic function, which is applied to the source instance, dispatching on its class to select the method which implements the appropriate conversion. Thus, having defined a new class to which it may be desirable to convert instances of other classes, the programmer defines a generic function:

(defgeneric (converter new-class) (instance)) Hereafter, new converter methods may be defined for new-class using a similar extended syntax for defmethod: (defmethod (converter new-class) ((instance other-class))) The conversion is implemented by defining methods on the converter for new-class which specialize on the source class. This is also how methods are documented in this text: by an entry for a method on the converter function for the target class. In general, the method for a given source class is defined in the section about that class, for example, converters from one kind of collection to another are defined in section ?? , converters from string in section ?? , etc..


convert : function

Arguments

object
An instance of some class to be converted to an instance of class.
class
The class to which object is to be converted.

Result

Returns an instance of class which is equivalent in some class-specific sense to object, which may be an instance of any type. Calls the converter function associated with class to carry out the conversion operation. An error is signalled (condition: no-converter) if there is no associated function. An error is signalled (condition: no-applicable-method) if there is no method to convert an instance of the class of object to an instance of class.


<conversion- condition> : <condition>
This is the general condition class for all conditions arising from conversion operations.

Initialization options

source : <object>
The object to be converted into an instance of target-class.
target-class : <class>
The target class for the conversion operation.

Remarks

Should be signalled by convert or a converter method.


converter : function

Arguments

target-class
The class whose set of conversion methods is required.

Result

The accessor returns the converter function for the class target-class. The converter is a generic-function with methods specialized on the class of the object to be converted.


(setter converter) : setter function

Arguments

target-class
The class whose converter function is to be replaced.
generic-function
The new converter function.

Result

The new converter function. The setter function replaces the converter function for the class target-class by generic-function. The new converter function must be an instance of .

Remarks

Converter methods from one class to another are defined in the section pertaining to the source class.

See also:

Converter methods are defined for collections (?? ), double float (?? ), fixed precision integer (?? ), string (?? ), symbol (?? ), vector (?? ).
Julian Padget, jap@maths.bath.ac.uk, this version February 7, 1995