If one of the input parameters is a list of unknown length, combine the "several possible cases" template with the "compound data type" template.
Data definition:so the body will be a cond with two cases:
a list-of-unknown-length is either
- empty , or
- (cons something some-other-list-of-unknown-length)
(define (template-for-list the-list)
(cond [(empty? the-list) ...]
[(cons? the-list) ...]))
Furthermore, if the list is a cons, you know that it has a
first and a rest, so by the "compound data type"
rule you can expand the template to
(define (template-for-list the-list)
(cond [(empty? the-list) ...]
[(cons? the-list)
... (first the-list) ...
... (rest the-list) ...]))
What you can do with "(first the-list)" and "(rest the-list)"
depends on their types. Since rest always returns a list of
the same type as it was given (only one item shorter), the most likely
thing to do with "(rest the-list)" is to apply the same
function to it:
(define (template-for-list the-list)
(cond [(empty? the-list) ...]
[(cons? the-list)
... (first the-list) ...
... (template-for-list (rest the-list)) ...]))