; ======================================================================
;
; Structure and Interpretation of Computer Programs
; (trial answer to excercises)
;
; 计算机程序的构造和解释(习题试解)
;
; created: code17 07/28/05
; modified:
; (保持内容完整不变前提下,可以任意转载)
; ======================================================================
;; SICP No.2.27
(define (deep-reverse x)
(if (pair? x)
(append (deep-reverse (cdr x)) (list (deep-reverse (car x))))
x))
;; Test-it:
;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;; > (define x (list (list 1 2) (list 3 4)))
;; > x
;; ((1 2) (3 4))
;; > (deep-reverse x)
;; ((4 3) (2 1))