第 4 章,HtDP。
注意:我在其他问题中也看到了这一点。
是出于清晰的原因还是算法的原因,我不知道,基本情况返回空而不是列表本身是空的。
例子:
; List-of-numbers -> List-of-numbers
; compute the weekly wages for all given weekly hours
(define (wage* alon)
(cond
[(empty? alon) empty] ;<---- see here
[else (cons (wage (first alon)) (wage* (rest alon)))]))
; Number -> Number
; compute the wage for h hours of work
(define (wage h)
(* 12 h))
我认为这同样正确。
; List-of-numbers -> List-of-numbers
; compute the weekly wages for all given weekly hours
(define (wage* alon)
(cond
[(empty? alon) alon] ;<---- see here
[else (cons (wage (first alon)) (wage* (rest alon)))]))
; Number -> Number
; compute the wage for h hours of work
(define (wage h)
(* 12 h))