fork(2) download
  1. (defun my-reverse-1 (l)
  2. (let ((x (car l))
  3. (xs (cdr l)))
  4. (cond ((consp x) (my-reverse-1 (cons (cdr x) (cons (car x) xs))))
  5. ((null x) xs)
  6. (t (my-reverse-1 (cons xs (cons x nil)))))))
  7.  
  8. (defun my-reverse-2 (l)
  9. (my-reverse-2-aux l nil))
  10.  
  11. (defun my-reverse-2-aux (l a)
  12. (if (null l)
  13. a
  14. (my-reverse-2-aux (rest l) (cons (first l) a))))
  15.  
  16. ;; CL-USER> (my-reverse-1 (list 1 2 3 4))
  17. ;; 0: (MY-REVERSE-1 (1 2 3 4))
  18. ;; 1: (MY-REVERSE-1 ((2 3 4) 1))
  19. ;; 2: (MY-REVERSE-1 ((3 4) 2 1))
  20. ;; 3: (MY-REVERSE-1 ((4) 3 2 1))
  21. ;; 4: (MY-REVERSE-1 (NIL 4 3 2 1))
  22. ;; 4: MY-REVERSE-1 returned (4 3 2 1)
  23. ;; 3: MY-REVERSE-1 returned (4 3 2 1)
  24. ;; 2: MY-REVERSE-1 returned (4 3 2 1)
  25. ;; 1: MY-REVERSE-1 returned (4 3 2 1)
  26. ;; 0: MY-REVERSE-1 returned (4 3 2 1)
  27. ;; (4 3 2 1)
  28. ;; CL-USER> (my-reverse-2 (list 1 2 3 4))
  29. ;; 0: (MY-REVERSE-2 (1 2 3 4))
  30. ;; 1: (MY-REVERSE-2-AUX (1 2 3 4) NIL)
  31. ;; 2: (MY-REVERSE-2-AUX (2 3 4) (1))
  32. ;; 3: (MY-REVERSE-2-AUX (3 4) (2 1))
  33. ;; 4: (MY-REVERSE-2-AUX (4) (3 2 1))
  34. ;; 5: (MY-REVERSE-2-AUX NIL (4 3 2 1))
  35. ;; 5: MY-REVERSE-2-AUX returned (4 3 2 1)
  36. ;; 4: MY-REVERSE-2-AUX returned (4 3 2 1)
  37. ;; 3: MY-REVERSE-2-AUX returned (4 3 2 1)
  38. ;; 2: MY-REVERSE-2-AUX returned (4 3 2 1)
  39. ;; 1: MY-REVERSE-2-AUX returned (4 3 2 1)
  40. ;; 0: MY-REVERSE-2 returned (4 3 2 1)
  41. ;; (4 3 2 1)
Success #stdin #stdout 0s 10512KB
stdin
Standard input is empty
stdout
Standard output is empty