I am pretty new with Clojure. I have one Java method including a boolean variable and I want to rewrite this method to use it with the same functional in Clojure as well. But I couldn't find how to set the boolean value true and false in run-time in Clojure.
The following snippet basically emphasize only the boolean part, It is difficult to think for me to write this in a functional way.
int calculate(...){
int y = 0;
boolean flag = false;
foreach(...){
if(!flag){
y = 1;
flag = true;
}
else{
y = -1;
flag = false;
}
}
return y;
}
Here is the my first attempt in Clojure:
(defn calculate [...]
( ??flag?? -> I do not know which macro I should use over here
(doseq [x ...]
(if (false? flag) (do 1 (set the flag true))
(do -1 (set the flag false)))))
How can I implement the same concept in Clojure?
(defn calculate [y flag] ..)