Created
March 3, 2011 17:09
-
-
Save timmc/853113 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
(defn replace-1 | |
"Replace the first x in coll such that (pred x) is true with (gen x). | |
Not tail-recursive." | |
[coll pred gen] | |
(if (seq coll) | |
(if (pred (first coll)) | |
(conj (rest coll) | |
(gen (first coll))) | |
(conj (replace-1 (rest coll) pred gen) | |
(first coll))) | |
coll)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment