灯下 登录
计算机科学 / SICP / 3.3.3 Representing Tables

Exercise 3.24 · 习题

Exercise 3.24: In the table implementations

above, the keys are tested for equality using equal? (called by

assoc). This is not always the appropriate test. For instance, we

might have a table with numeric keys in which we don’t need an exact match to

the number we’re looking up, but only a number within some tolerance of it.

Design a table constructor make-table that takes as an argument a

same-key? procedure that will be used to test “equality” of keys.

Make-table should return a dispatch procedure that can be used to

access appropriate lookup and insert! procedures for a local

table.

练习 3.24:在上面的表实现中,键的相等性检测使用 equal?(由 assoc 调用)。但这并不总是合适的检测方式。例如,我们可能有一个以数值为键的表,查找时不需要精确匹配,只需在某个容差范围内即可。请设计一个表构造函数 make-table,它接受一个 same-key? 过程作为参数,该过程将用于检测键的“相等性”。make-table 应返回一个分派过程,可用于访问适用于本地表的 lookup 和 insert! 过程。