Created
November 25, 2012 06:42
-
-
Save dingbat/4142657 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (uncycle lst) (uncycle2 lst lst)) ; recursive handle | |
| (define (uncycle2 lst orig) (if (null? lst) | |
| '() ; means it wasn't actually a cycle, but we forgive | |
| (if (eq? (cdr lst) orig) ; base case. (if the cdr is the list itself) | |
| (list (car lst)) ; return just the element previous | |
| (cons (car lst) ; otherwise, recurse. add the prev element | |
| (uncycle2 (cdr lst) orig))))) ; onto the uncycle'd next part of the list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment