fork download
  1. #!/usr/bin/racket
  2. #lang scheme
  3.  
  4. (define (trace xs msg)
  5. (display xs)
  6. (display " in ")
  7. (display msg)
  8. (newline))
  9.  
  10. (define (reverse items)
  11. (trace items "reverse")
  12. (define (iter xs result)
  13. (if (null? xs)
  14. result
  15. (iter (cdr xs) (cons (car xs) result))))
  16. (iter items '()))
  17.  
  18. (define (deep-reverse items)
  19. (trace items "deep-reverse")
  20. (if (not (pair? items))
  21. items
  22. (reverse (map deep-reverse items))))
  23.  
  24. ; ((1 2) (3 4))
  25. (define x (list (list 1 2) (list 3 4)))
  26.  
  27. ;(display x)
  28. ;(newline)
  29.  
  30. ;(display (reverse x))
  31. ;(newline)
  32.  
  33. ; (deep-reverse ((1 2) (3 4)) )
  34. ; (reverse ( '( ((reverse (deep-reverse '(1 2))) (reverse (deep-reverse '(3 4))) ))
  35. ; (reverse ( '( (reverse '((deep-reverse 1) (deep-reverse 2)) (reverse '((deep-reverse 3) (deep-reverse 4))))))
  36. ; (reverse ( '( (reverse '(1 2)) (reverse '(3 4)))))
  37. ; (reverse ( '( (2 1) (4 3) )))
  38. ; ((4 3) (1 2))
  39.  
  40. (display (deep-reverse x))
  41. (newline)
  42.  
Runtime error #stdin #stdout #stderr 0.03s 8616KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: In procedure primitive-load:
ERROR: In procedure skip_block_comment: /home/K0U0ZC/prog.scm:42:1: unterminated `#! ... !#' comment