- Code: Select all
(define (count-pattern pattern lst)
(if (null? lst) 0
(+ (if (check-pattern pattern lst) 1 0) (count-pattern pattern (cdr lst)))))
(define (check-pattern pattern lst)
(cond
((null? pattern) #t)
((null? lst) #f)
(else (and (equal? (car pattern) (car lst)) (check-pattern (cdr pattern) (cdr lst))))))
Is there a more elegant way to write this as one function that I'm not seeing, or is what I did acceptable in this case?
