我有两个定义,一个家谱和一个人。
; a family-tree is:
; (make-person list-of-family-tree symbol number symbol)
; a person is:
; (define-struct person [children name date eyes])
我需要创建一个“相互递归”函数来计算树中后代的数量(包括人)。但是如果满足条件,我无法弄清楚如何让 cond 做不止一件事。
IE:
(define (count-descendants person1)
(cond [(empty? (person-children person1)) +0]
[else (count-descendants (first (person-children person1)))/*also +1 here*/
(count-descendants (rest (person-children person1)))/*also +1 here*/]))
知道如何递归调用列表其他部分的函数并添加一个吗?