Last active
May 31, 2019 21:38
-
-
Save fselcukcan/1b013def06ab6df66f3532ed5131bb52 to your computer and use it in GitHub Desktop.
reverse
This file contains 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
(defun reverse (l acc) | |
(cond | |
((null l) acc) | |
(t (reverse (cdr l) (cons (car l) acc))))) | |
; (reverse '(7 5 1 3)) => (3 1 5 7) |
This file contains 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 | |
(lambda (l acc) | |
(cond | |
((null? l) acc) | |
(else (reverse (cdr l) (cons (car l) acc)))))) | |
; (reverse '(7 5 1 3) '()) => (3 1 5 7) | |
;; can be written with a helper function | |
(define reverse | |
(lambda (l) | |
(reverse-aux l (quote ())))) | |
(define reverse-aux | |
(lambda (l acc) | |
(cond | |
((null? l) acc) | |
(else (reverse (cdr l) (cons (car l) acc)))))) | |
; (reverse '(7 5 1 3)) => (3 1 5 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment