0
What difference between for
and doseq
?
I wrote a program, which returns me the highest value within the parameters informed. Note: I know that there is a function max
and max-key
, but I don’t want to use them because I want to train the language.
Example:
Using doseq
, works.
(defn valorMaximo [& num]
(let [x (atom (first num))]
(doseq [i num] (when (> i @x) (reset! x i)) ) @x))
Using for
, doesn’t work.
(defn valorMaximo2 [& num]
(let [x (atom (first num))]
(for [i num :when (> i @x)] (reset! x i)) @x))
First, thank you, I had seen the function
reduce
but had not understood its functioning. but now it was very clear, thank you– Thomas Erich Pimentel