Patterns: recognition of patterns is an enormously useful skill to develop
(define (mystery1 sent) ; What does this function do? (cond ((empty? sent) sent) (else (se (* 2 (first sent)) (mystery1 (bf sent)))))) (define (mystery2 sent) ; What does this function do? (cond ((empty? sent) sent) ((odd? (first sent)) (se (first sent) (mystery2 (bf sent)))) (else (mystery2 (bf sent))))) (define (mystery3 sent) ; What does this function do? (cond ((empty? sent) 0) ; Why is this tested first? ((= (count sent) 1) (first sent)) ; Why is this tested at all? (else (mystery3 (se (bl (bl sent)) (+ (last sent) (last (bl sent)))))))) ; What is happening?
PROBLEMS (All to be done using recursion, not existing HOFs)
1. Write a function delete-first that takes a sentence of words and removes the first letter of each word. (You may assume no empty words are in the sentence.)
> (delete-first '(the gate)) (he ate)
2. Write a function int-sqrts that takes a sentence of numbers and returns a sentence containing only those numbers that have integer square roots. You may find the integer? predicate useful.
> (int-sqrts '(9 2 3 4 6 5 7 8 1)) (9 4 1)
3. Write a function acc-word that does the same thing as accumulate word.
> (acc-word '(now here man)) nowhereman