Symbolic Processing in Scheme II: class notes

(define (dec->bin x L) (if (= x 0) L (if (odd? x) (dec->bin (/ x 2) (cons 1 L)) (dec->bin (/ x 2) (cons 0 L))))) (dec->bin 26 '()) ->(dec->bin 13 '(0)) ->(dec->bin 6 '(1 0)) ->(dec->bin 3 '(0 1 0)) ->(dec->bin 1 '(1 0 1 0)) ->(dec->bin 0 '(1 1 0 1 0)) -> '(1 1 0 1 0) (define (bin->dec L x) (if (null? L) x (bin->dec (rest L) (+ (first L) (* 2 x))))) (bin->dec '(1 0 0 1 0) 0) ->(bin->dec '(0 0 1 0) (+ 1 (* 2 0))) ->(bin->dec '(0 0 1 0) 1) ->(bin->dec '(0 1 0) (+ 0 (* 2 1))) ->(bin->dec '(0 1 0) 2) ->(bin->dec '(1 0) (+ 0 (* 2 2))) ->(bin->dec '(1 0) 4) ->(bin->dec '(0) (+ 1 (* 2 4))) ->(bin->dec '(0) 9) ->(bin->dec '() (+ 0 (* 2 9))) ->(bin->dec '() 18) -> 18 (define (sq x) (* x x)) -> (map sq '(1 2 3 4 5)) -> '((sq 1) (sq 2) (sq 3) (sq 4) (sq 5)) -> '(1 4 9 16 25) -> (apply + '(1 2 3 4 5)) -> (+ 1 2 3 4 5) -> 15 -> (apply + (map sq '(1 2 3 4 5))) -> (apply + '(1 4 9 16 25)) -> 55 (define (li x) (string-append "<li>" x "</li>")) (define (ul x) (string-append "<ul>" (apply string-append (map li x)) "</ul>")) (ul '("a" "b" "c")) ->(string-append "<ul>" (apply string-append (map li '("a" "b" "c"))) "</ul>") ->(string-append "<ul>" (apply string-append (list (li "a") (li "b") (li "c"))) "</ul>") ->(string-append "<ul>" (apply string-append (list "<li>a</li>" "<li>b</li>" "<li>c</li>"))) "</ul>") ->(string-append "<ul>" "<li>a</li><li>b</li><li>c</li>" "</ul>") ->"<ul><li>a</li><li>b</li><li>c</li></ul>"