我希望程序计算在表达式中找到特定子字符串的次数。我写了下面的代码,但是我没有得到预期的输出。
(define (count-occurrences s slist)
(if (null? slist)
0
(+ (count-occurrences-in-s-sexp s (car slist))
(count-occurrences s (cdr slist)))))
(define (count-occurrences-in-s-sexp s sexp)
(if (symbol? sexp)
(if (eqv? sexp s) 1 0)
(count-occurrences s sexp)))
Input: (count-occur '(a x) '((x y z) x (z (a x) y)) )
Output: 0
Expected O/p : 1
Input: (count-occur 'x '((x y z) x (z (a x) y)))
Output: 3
Expected O/p : 3
当我输入list时。我没有得到预期的输出。有人能帮我吗?/
您希望使用equal?
而不是eqv?
来确定两个列表是否相同