[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
COERCE (not urgent)
- To: email@example.com
- Subject: COERCE (not urgent)
- From: kempf%hplabsz@hplabs.HP.COM
- Date: Thu, 01 Oct 87 10:25:39 MST
Since COERCE is a Cleanup Committee issue, there is no urgency to finish
electronic mail discussion for Dick and Linda before next Fri., but I
thought I would post it so that people can start thinking about it.
I'll summarize discussion by Oct. 17.
ISSUE: How should (or even should) COERCE be changed to accommodate
REMARK: CLOS already has two mechanisms of changing an object's class:
1) Class redefinition (largely hidden, automatic, with some
user defined hooks, smashes the instance)
2) CHANGE-CLASS (smashes the instance)
1) Leave COERCE as it currently is. That is, make no CLOS
2) Keep COERCE a function and have an internal generic function,
COERCE-USING-CLASS handle coercion when the second argument is
a class object, or the type specifier is for a CLOS class.
3) Make COERCE a generic function, with one method handling coercion
when the second argument is a type specifier and one when it is
a class object. Note that the type specifier method would need to
handle the case of a type specifier for a CLOS class by using SYMBOL-CLASS
to get the class, then reinvoking the generic function.
SEMANTICS FOR CLOS OBJECTS:
COERCE creates a new instance of the second argument, initializing
according to the initialization protocol for the class, and then copies
named slots common between the two instances, modulo type errors.
If the first argument is already of the class indicated by the second
argument, it is returned without copying.
Note that this corresponds roughly with the current semantics when the
first argument is a sequence and the second argument is a subtype
ALTERNATIVE ADVANTAGES AND DISADVANTAGES:
The advantages of 1) are obvious: no changes needed in the base
Common Lisp. The advantage of 2) is that the class and type specifier
functionality are segregated under different names, since
the new generic function takes care of coercion for CLOS.
The advantage of 3) is that it reduces name proliferation, and integrates
CLOS more tightly into the language. In addition, users can write new
methods which discriminate on the first argument, and take a type
specifier for the second.
The disadvantages of 1) are that users must write their own methods
for coercion. The disadvantage of 2) is that it introduces Yet Another
metaclass function (COERCE-USING-CLASS). The disadvantages of 3) are
that users might do something dangerous with existing type specifiers
(like define a method that coerces an integer into a list).