University of California, Berkeley
EECS Department - Computer Science Division

CS3 Lecture 8
Recursion ­ Patterns (cont'd)

Thanks to Oliver Grillmeyer and Brendan Ferguson for many of the ideas for these notes


Overview of today's lecture


Answers to questions that have come up

Review


Recursion and Patterns (cont'd)

Tracing is a great tool to understand the process:

: (define (my-count s)
    (if (empty? s)
        0
        (+ 1 (my-count (bf s)))))
my-count

: (trace my-count)
my-count

: (my-count '(cs3 is the best class))
Entry (my-count '(cs3 is the best class))
|Entry (my-count '(is the best class))
| Entry (my-count '(the best class))
|  Entry (my-count '(best class))
|  |Entry (my-count '(class))
|  | Entry (my-count '())
|  | ==> 0
|  |==> 1
|  ==> 2
| ==> 3
|==> 4
==> 5
5

: (untrace my-count)
my-count

: (my-count '(cs3 is the best class))
5

Continuation of patterns

That's not all the patterns you'll see

Almost all the recursive patterns which operate on sentences also operate on words, with slight to no modifications.


Summary

Next Time

Puzzle : Socks in Drawers

Game : Achi ["Pentagames" by Pentagram, Fireside Publishing, 1990]


WWW Maven: Dan Garcia (ddgarcia@cs.berkeley.edu) Send me feedback

Dan Garcia Berkeley Computer Science