Skip to content

Instantly share code, notes, and snippets.

@davidrupp
Last active August 29, 2015 14:19
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 davidrupp/8ecce770be8cadc77f70 to your computer and use it in GitHub Desktop.
Save davidrupp/8ecce770be8cadc77f70 to your computer and use it in GitHub Desktop.
alter-var-root-constantly-3
(def thing 1)
; general form is
; (alter-var-root var-to-be-altered
; function-to-apply-to-old-value)
(alter-var-root #'thing inc) ; value of thing is now 2
; equivalently ...
(alter-var-root #'thing (fn [old-val] (inc old-val))) ; value of thing is now 3
; also equivalently ...
(alter-var-root #'thing #(inc %1)) ; value of thing is now 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment