Last active
December 30, 2015 05:19
-
-
Save maxcountryman/7781769 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
(definterface INode | |
(getCar []) | |
(getCdr []) | |
(setCar [x]) | |
(setCdr [x])) | |
(deftype Node [^:volatile-mutable car ^:volatile-mutable cdr] | |
INode | |
(getCar [_] car) | |
(getCdr [_] cdr) | |
(setCar [this x] (set! car x)) | |
(setCdr [this x] (set! cdr x)) | |
clojure.lang.ISeq | |
(first [this] this) | |
(next [_] cdr)) | |
(defn new-node [car & [cdr]] | |
(Node. car cdr)) | |
(defn list-eval [l] | |
(let [l (reverse l)] | |
(loop [cur (first l) more (next l) nodes nil] | |
(if-not cur | |
nodes | |
(recur (first more) (next more) (new-node cur nodes)))))) | |
(prn (-> (list-eval (list 1 2 3 4)) first .getCar)) ;; => 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment