We started learning about lists. (Chapter 22-23 in Picturing Programs.) Picturing Programs can be kind of long-winded in these chapters.
Things to know:
empty-list
or (list )
or '()
empty?
: list -> booleanfirst
: list of Things -> Thingrest
: list -> listlist*
to add to the front of a list(-> (listof number?) number?)
List processing always begins with a choice (conditional) to see if the list is empty or not. The else clause almost always contains (…. (first the-list) … (rest the-list)…) combined in some way.
Simplified design process:
The skeleton is very important for list-processing problems. It usually has a form like this:
(define (do-something the-list)
(cond [(empty? the-list) ...]
[else
(... (first the-list) ...
(do-something (rest the-list)))]))
Write down a skeleton like that when you are working through a list.