Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 2a9dba2f9e
Fetching contributors…

Cannot retrieve contributors at this time

31 lines (25 sloc) 0.705 kB
;; Example 2.27
(define x (list (list 1 2) (list 3 4)))
x
(define (my-reverse lst)
(define (iter l result)
(if (null? l)
result
(iter (cdr l)
(cons (car l) result))))
(iter lst ()))
(my-reverse x)
;; When constructing reverse list from
;; (car list-on-this-iteration) and result
;; we need to check, whether list-on-this-iteration is list
;; if true - deep-reverse it.
(define (deep-reverse items)
(define (iter l result)
(if (null? l)
result
(iter (cdr l)
(cons (if (list? (car l)) (deep-reverse (car l))
(car l))
result))))
(iter items ()))
(deep-reverse x)
Jump to Line
Something went wrong with that request. Please try again.