灯下 登录
计算机科学 / SICP / 2.5.2 Combining Data of Different Types

Exercise 2.82 · 习题

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.)

练习 2.82:说明如何将 apply-generic 推广到在多参数的一般情形下处理强制转换。一种策略是尝试将所有参数强制转换为第一个参数的类型,然后转换为第二个参数的类型,依此类推。举出一个例子,说明这种策略(以及上面给出的两参数版本)不够通用的情形。(提示:考虑表中存在某些适合的混合类型操作但不会被尝试的情况。)