Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save upgradingdave/68bf9554a92ae520a626190f7d69c9b6 to your computer and use it in GitHub Desktop.
Save upgradingdave/68bf9554a92ae520a626190f7d69c9b6 to your computer and use it in GitHub Desktop.
Clojure linked list using defrecord
(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)))
@upgradingdave
Copy link
Author

How can I optimize add-node so it doesn't stackoverflow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment