Last active
December 23, 2015 08:19
-
-
Save WillNess/6606865 to your computer and use it in GitHub Desktop.
rplac1 - replace 1st occurrence in nested list
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 (rplac1 xs a b) | |
| (let g ((xs xs) (f #f) (k (lambda (x y) x))) ; http://ideone.com/AbWKxS | |
| (cond | |
| (f (k xs f)) ; shortcut! | |
| ((null? xs) (k xs f)) ; http://stackoverflow.com/q/16550176/849891 | |
| ((not (pair? xs)) ; http://stackoverflow.com/q/16444290/849891 | |
| (if (eq? xs a) (k b #t) (k xs f))) ; not f! | |
| (else | |
| (g (car xs) f (lambda (x f) | |
| (g (cdr xs) f (lambda (y f) | |
| (if (not f) | |
| (k xs f) | |
| (k (cons x y) f)))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment