Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created January 17, 2017 00:13
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 michalmarczyk/1e624be27d6a6da690f2fdfbb47cb960 to your computer and use it in GitHub Desktop.
Save michalmarczyk/1e624be27d6a6da690f2fdfbb47cb960 to your computer and use it in GitHub Desktop.
Clojure local shadowing, loop semantics
;;; See the comment threads here:
;;; http://stackoverflow.com/questions/41677617/are-all-variables-in-clojure-constant
(loop [x 1
f (fn [] x)]
(if (== 1 x)
(recur 0 f)
(f)))
;= 1
(loop [x 10
fs []]
(if (pos? x)
(recur (dec x)
(conj fs (fn [] x)))
(mapv #(%) fs)))
;= [10 9 8 7 6 5 4 3 2 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment