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