;2.20
(define (check i)
(if (= 0 (remainder i 2)) 0 1))
(define (same-parity . w)
(define flag (check (car w)))
(define (iter i items)
(if (= i (length w))
(my-reverse items)
(if (= (check (list-ref w i))
flag)
(iter (+ 1 i) (cons (list-ref w i) items))
(iter (+ 1 i) items))))
(iter 0 '()))
;midterm examle 1 problem 5
(define (vowel? letter)
(member? letter '(a e o u i)))
(define (syllables wds)
(define (iter letter count strings)
(cond ((= '() (first strings)) count)
((vowel? (first strings)) (if (not (vowel? letter))
(iter (first strings) (+ 1 count) (butfirst strings)))
)
(else (iter (first strings count (butfirst strings))))))
(iter '() 0 wds))
;map tree
(define (scale-tree tree factor)
(cond ((null? tree) '())
((not (pair? tree)) (* tree factor))
(else (cons (scale-tree (car tree) factor)
(scale-tree (cdr tree) factor)))))
(define (s-tree tree factor)
(map (lambda (sub-tree)
(if (pair? sub-tree)
(scale-tree sub-tree factor)
(* sub-tree factor)))
tree))
2.20
最新推荐文章于 2024-02-20 21:34:25 发布