mit-scheme

How to compute the number of times pattern in one list appears in other list in Scheme

人走茶凉 提交于 2019-11-28 10:59:42
问题 I am stuck up in a Scheme program for about 5 hours. The program that I am working on should take two lists as input and then compute the number of times the pattern within the first list appears on the second list. For example : > (patt '(b c) '(a b c d e b c)) ==> answer = 2 (patt '(a b c) '(a b c a b c d e a b c c c)) ==> answer = 3 (patt '((a b) c) '(a b (a b) c d e b c)) ==> answer = 1 Below is the code that I have till now. (define (patt lis1 lis2) (cond ((null? lis1) 0) ((null? lis2) 0