Skip to content

Instantly share code, notes, and snippets.

@davidrupp
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save davidrupp/8ecce770be8cadc77f70 to your computer and use it in GitHub Desktop.

Select an option

Save davidrupp/8ecce770be8cadc77f70 to your computer and use it in GitHub Desktop.

Revisions

  1. davidrupp revised this gist Apr 23, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.clj
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    (def thing 1)

    ; general form is (alter-var-root var-to-be-altered function-to-apply-to-calculate-the-new-value)
    ; 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
  2. davidrupp revised this gist Apr 23, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.clj
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    ; general form is (alter-var-root var-to-be-altered function-to-apply-to-calculate-the-new-value)
    (def thing 1)

    ; general form is (alter-var-root var-to-be-altered function-to-apply-to-calculate-the-new-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
  3. davidrupp created this gist Apr 23, 2015.
    7 changes: 7 additions & 0 deletions gistfile1.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    ; general form is (alter-var-root var-to-be-altered function-to-apply-to-calculate-the-new-value)
    (def thing 1)
    (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