Created
June 16, 2011 14:32
-
-
Save klandergren/1029332 to your computer and use it in GitHub Desktop.
SunnyCloud: 2.17 and 2.18
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
;; 2.17 | |
(define (last-pair list) | |
(if (= (cdr list) ()) | |
(car list)) ;; I think paren error on this line. | |
(cdr list)) ;; not calling last-pair recursively | |
;; 2.18 fails for me | |
(define (reverse list) | |
(= (cdr list) ()) ;; missing an if statement | |
(= new-list (cons (car list) ()) | |
(cons (car list) (car new-list))) | |
;; Think of 2.18 in terms of 2.17: if you can find the last pair of a list | |
;; can't you call that recursively to build a new list last-element to first? | |
;; Testing | |
(reverse (list 1 4 9 16 25)) ;; => (list 25 26 9 4 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out my fork..