Skip to content

Instantly share code, notes, and snippets.

@maxcountryman
Last active December 30, 2015 05:19
Show Gist options
  • Save maxcountryman/7781769 to your computer and use it in GitHub Desktop.
Save maxcountryman/7781769 to your computer and use it in GitHub Desktop.
(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