Skip to content

Instantly share code, notes, and snippets.

@ldcc
Last active May 23, 2019 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldcc/c68346c985533d9de1deb5db52862cb8 to your computer and use it in GitHub Desktop.
Save ldcc/c68346c985533d9de1deb5db52862cb8 to your computer and use it in GitHub Desktop.
list reversal
(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