Problem PS.4.2.4: Counting utterances


In this problem we're going to build some procedures for counting patterns in sequences of words. Previously we did this using histograms. Here we are going to directly match patterns.

    Part 1: Did I really say it that many times?

    Write a procedure (match pattern text), that takes a list of symbols, and a second list of symbols, and returns the number of times that exact sequence of symbols of the pattern appears in the text. So if we have
    (define *test* '(a b c a b a b a b c  b c b c a b c))
    
    then
    (match '(a b c) *test*) => 3
    (match '(a b c) '()) => 0
    (match '(a b c d) *test*) => 0
    (match '(a) *test*) => 5
    

    You may find it helpful to use an internal prodedure that keeps track of where you are in terms of matching the pattern to a spot in the text and where in the list of text words you started this particular match.


    Below is an applet that flashes matching parens and does Scheme indenting when you type Tab.


    Part 2: Um, did I um really um say it um that um many times?

    Write a procedure match*, with a similar behvior to match, except that if a symbol in the pattern is the special symbol *, this can match to ANY symbol.


    Below is an applet that flashes matching parens and does Scheme indenting when you type Tab.