Created
August 2, 2018 18:13
-
-
Save upgradingdave/68bf9554a92ae520a626190f7d69c9b6 to your computer and use it in GitHub Desktop.
Clojure linked list using defrecord
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
(defrecord ListNode [value next]) | |
(defn add-node [^ListNode curr v] | |
(if curr | |
(assoc curr :next (add-node (:next curr) v)) | |
(ListNode. v nil))) | |
(def result | |
(loop [l nil i 0] | |
(if (< i 100000) | |
(recur (add-node l i) (inc i)) | |
l))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I optimize
add-node
so it doesn't stackoverflow?