(wat-aro)

無職から有職者にランクアップしました

SICP 問題 2.27

(define x (list (list 1 2) (list 3 4)))

(define (reverse items)
  (if (null? items)
      items
      (append (reverse (cdr items)) (list (car items)))))

(define (deep-reverse items)
  (cond ((null? items) nil)
        ((pair? items) (append (deep-reverse (cdr items))
                               (list (deep-reverse (car items)))))
        (else items)))
gosh> (deep-reverse x)
((4 3) (2 1))
gosh> (define y (list (list 1 2) (list 3 4 (list 5 6 7))))
y
gosh> (deep-reverse y)
(((7 6 5) 4 3) (2 1))