Skip to content

Instantly share code, notes, and snippets.

@miyukino
Created May 26, 2013 08:43
Show Gist options
  • Save miyukino/5652111 to your computer and use it in GitHub Desktop.
Save miyukino/5652111 to your computer and use it in GitHub Desktop.
Scheme: Deep List Reverse
;; Exp. (list-reverse '(1 (2 3) (4 (5 6) (7 8 (9))))) ==> ((((9) 8 7) (6 5) 4) (3 2) 1)
(define (list-reverse L)
(if (null? L) L
(if (list? (car L))
(append (list-reverse (cdr L)) (cons (list-reverse (car L)) '()))
(append (list-reverse (cdr L)) (list (car L))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment