Skip to content

Instantly share code, notes, and snippets.

@9re
Created September 21, 2011 16:22
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 9re/1232527 to your computer and use it in GitHub Desktop.
Save 9re/1232527 to your computer and use it in GitHub Desktop.
re-construction of 'reverse' with only foldr and cons
(define (foldr f z ls)
(if (null? ls)
z
(f (car ls)
(foldr f z (cdr ls)))))
(define (revr ls)
((foldr (lambda (x f)
(lambda (a)
(f (cons x a))))
(lambda (x) x)
ls)
'()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment