【发布时间】:2014-02-23 15:41:31
【问题描述】:
我正在尝试编写一个函数,该函数接受两个列表(必须等长),然后遍历每个列表来比较各个项目。
例如:(1 2 3) 和 (2 4 5) 将返回 true,因为列表 2 的每个元素都大于列表 1 中的相应元素。(1 2 3) 和 (0 4 1) 将返回 false,(1 2 3) 和(1 2 3 4) 因为它们的大小不同。使用 Dr Racket
(define (each-bigger? a-lon another-lon)
(cond
(if
[(= (length a-lon) (length another-lon))true]
(then
[(> (first a-lon) (first another-lon))true]
(then
[(> (rest a-lon) (rest another-lon))true]
[else false])))))
这没用。
【问题讨论】: