下面这些给我留下了很深的印象
always ask null? as the first question in expressing any function.
when building a list, describe the first typical element, then cons it onto the natural recursion.
always change at least one argument when use recurring.it must be changed to be closer to termination.
The changing argument must be tested in the termination condition. when using cdr, test termination
with null?.
when recurring on a list of atomes, lat , use (cdr lat).
when recurring on a number, n, use (sub1 n),
when recurring on a list of Scheme-expressions, l, ask three questions.
(null? l)
(atom? (car l))
and else.
use (car l) and (cdr l) if neither (null? l) nor (atom? (car l)) are true.
#
eq? tests just for the same object (essentially a pointer comparison). This is fast, and can be used when searching for a particular object, or when working with symbols or keywords (which are always unique objects).
eqv? extends eq? to look at the value of numbers and characters. It can for instance be used somewhat like = (see Comparison) but without an error if one operand isn’t a number.
equal? goes further, it looks (recursively) into the contents of lists, vectors, etc. This is good for instance on lists that have been read or calculated in various places and are the same, just not made up of the same pairs. Such lists look the same (when printed), and equal? will consider them the same.
Generally eqv? below should be used when comparing numbers or characters.
阅读(1342) | 评论(0) | 转发(0) |