Created
August 30, 2009 21:17
-
-
Save aaronfeng/178132 to your computer and use it in GitHub Desktop.
Little Schemer to Clojure translation
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 firsts [l] | |
(cond (empty? l) '() | |
:else (cons (ffirst l) (firsts (rest l))))) |
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 firsts2 | |
([l] | |
(firsts l '())) | |
([l acc] | |
(cond (empty? l) (reverse acc) | |
:else (recur (rest l) (cons (ffirst l) acc))))) |
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 insertR [new old lat] | |
(cond (empty? lat) '() | |
(= old (first lat)) (cons old (cons new (rest lat))) | |
:else (cons (first lat) (insertR new old (rest lat))))) |
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 insertR2 | |
([new old lat] (insertR2 new old lat '())) | |
([new old lat acc] (cond (empty? lat) acc | |
(= old (first lat)) (concat (reverse (cons new (cons old acc))) (rest lat)) | |
:else (recur new old (rest lat) (cons (first lat) acc))))) |
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 lat [l] | |
(cond (empty? l) true | |
(symbol? (first l)) (lat (rest l)) | |
:else false)) |
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 lat2 [l] | |
(cond (empty? l) true | |
(symbol? (first l)) (recur (rest l)) | |
:else false)) |
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 member? [a lat] | |
(cond (empty? lat) false | |
:else (or (= a (first lat)) | |
(member? a (rest lat))))) |
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 member2? [a lat] | |
(cond (empty? lat) false | |
:else (or (= a (first lat)) | |
(recur a (rest lat))))) |
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 rember [a lat] | |
(cond (empty? lat) '() | |
(= a (first lat)) (rest lat) | |
:else (cons (first lat) (rember a (rest lat))))) |
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 rember2 | |
([a lat] (rember a lat '())) | |
([a lat acc] | |
(cond (empty? lat) acc | |
(= a (first lat)) (concat acc (rest lat)) | |
:else (recur a (rest lat) (cons (first lat) acc))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment