Created
February 9, 2014 22:20
-
-
Save futuro/8906897 to your computer and use it in GitHub Desktop.
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
;;; Example implementation of a character list | |
(define chr_list '(#\w #\h #\a #\t)) | |
;;; Helper function to make reversing easy | |
(define (rev list) | |
(pushonto list '())) | |
;;; Function that does all of the work | |
(define (pushonto list1 list2) | |
;; If the first list is empty, return the second | |
(cond ((null? list1) list2) | |
;; Otherwise recurse | |
(else (pushonto (cdr list1) | |
;; Pushing the head of list1 onto list2, causing reversal | |
(cons (car list1) list2))))) | |
;;; The reverse of the reverse should be the original, so test that to make sure it is | |
(define (test-rev list) | |
(let ((reversed-list (rev list))) | |
(equal? (rev reversed-list) list))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment