How to increment by a number in Clojure? -


i know how increment x amount number, in other languages used do

foo += 0.1;

but have not idea how can done in clojure

variables immutable in clojure. should not try change value of foo, instead, "create" new foo:

(def foo2 (+ foo 0.1)) 

...or, if in loop, recur new value:

(loop [foo 5.0]   (when (< foo 9)     (recur (+ foo 0.1)))) 

...or, if foo atom, swap! new value:

(def foo (atom 5.0)) (swap! foo (partial + 0.1)) 

i recommend start reading the rationale of clojure.


Comments