Last active
May 23, 2019 11:04
-
-
Save ldcc/c68346c985533d9de1deb5db52862cb8 to your computer and use it in GitHub Desktop.
list reversal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define reverse | |
(letrec ([loop (λ (l1 l2) | |
(cond [(null? l1) l2] | |
[else (loop (cdr l1) (cons (car l1) l2))]))]) | |
(λ (l) (loop l '())))) | |
(reverse '(a b c d e f g)) | |
;; ⇒ '(g f e d c b a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment