scheme - let me know the error in the code and edit it -


define function called symcount takes symbol , list , returns number of times symbol occurs in list. if list contains sublists, occurrences should counted no matter how nested.

(define syscount(lambda (n x)   (if (empty? x)     0   (if (equal? n (car x))     (+ 1 syscount(n (cdr x)))))))  

this have written me pls

(define (syscount n x)              (if (null? x) 0                    (if (list? (car x))  (+ (syscount n (car x)) (syscount n (cdr x)))                           (+ (syscount n (cdr x)) (if (equal? n (car x)) 1 0)))))  

output is

(syscount '1 '(1 2 3))
1
(syscount '1 '(1 (1 2) 3))
2
(syscount '1 '(1 (1 2) 1 (1) 3))
4


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -