fork download
  1. ;#!/usr/bin/racket
  2. ;#lang scheme
  3.  
  4. (define (reverse items)
  5. (define (iter xs result)
  6. (if (null? xs)
  7. result
  8. (iter (cdr xs) (cons (car xs) result))))
  9. (iter items '()))
  10.  
  11. (define (deep-reverse items)
  12. (if (not (pair? items))
  13. items
  14. (reverse (map deep-reverse items))))
  15.  
  16. ; ((1 2) (3 4))
  17. (define x (list (list 1 2) (list 3 4)))
  18.  
  19. ;(display x)
  20. ;(newline)
  21.  
  22. ;(display (reverse x))
  23. ;(newline)
  24.  
  25. ; (deep-reverse ((1 2) (3 4)) )
  26. ; (reverse (map deep-reverse ((1 2) (3 4)) ))
  27. ; (reverse (reverse (map deep-reverse (1 2) )))
  28. ; (reverse (reverse (map
  29. (display (deep-reverse x))
  30. (newline)
  31.  
Success #stdin #stdout 0.03s 8616KB
stdin
Standard input is empty
stdout
((4 3) (2 1))