Exercise 2.82. Show how to generalize apply-generic to handle coercion in the general case of multiple arguments. One strategy is to attempt to coerce all the arguments to the type of the first argument, then to the type of the second argument, and so on. Give an example of a situation where this strategy (and likewise the two-argument version given above) is not sufficiently general. (Hint: Consider the case where there are some suitable mixed-type operations present in the table that will not be tried.)
假设我们需要定义个泛型的减法,能够实现像 scheme 的 - 一样的多参数的减法。题目中的设计对于
(- complex number number number ...)
这样的,是可以进行转换的–它会把之后所有的 number 全部转换为 complex,然后进行求解。但对于
(- number number complex complex ...)
这样的就不行,因为有的 complex 并不能转换为 number。于是提示转换错误。
我们应该做的是 raise,而不是 downcast。