(define (count-subexp exp x) (cond ((null? exp) 0) ((eq? (car exp) x) (+ 1 (count-subexp (cdr exp) x))) (else (count-subexp (cdr exp) x))))
示例应用:
(count-subexp '(a a b c d a) 'a) ; 返回 3
上一篇:编写一个Scheme EBNF语法的解析器。
下一篇:编写一个Scheme函数,用于返回两个列表中较长的列表,如果它们的长度相等,则返回true。