“如何设计程序”中的图65如下:
; Nelon -> Number
; determines the smallest number on l
(define (inf l)
(cond
[(empty? (rest l)) (first l)]
[else
(local ((define smallest-in-rest (inf (rest l))))
(cond
[(< (first l) smallest-in-rest) (first l)]
[else smallest-in-rest]))]))有没有人能解释一下变量的最小值是如何工作的。我在一个函数中得到了递归,但是一个变量把我搞糊涂了
发布于 2016-03-04 20:37:14
这只是以下内容的速记(正手;-):
(let ((smallest-in-rest (inf (rest l))))
(cond
[(< (first l) smallest-in-rest) (first l)]
[else smallest-in-rest]))let应该清楚地表明,我们只是存储(inf (rest l))的结果,以便只需在代码中编写一次,而不是为cond的每个分支编写一次。
https://stackoverflow.com/questions/35796087
复制相似问题