I have a small code that doesn’t want to work at all when I perform a loop like the following:
...
(defn my-function []
(println "Hi") ;this works
(for [i (range 10)] (println "Hello") ;this doesn't work!
)
)
...
I can’t understand what the problem is, all the code inside the loop seem to be ignored, while the “Hi” print without problems
I call ‘myfunction’ through a GUI button event, like this:
...
(.append output-text (with-out-str (time (my-function))))
...
Do you think the problem could reside in the GUI or something else I am missing? Any suggestion?
I know I should use the REPL to test it but it doesn’t work with Netbeans… :S
Thanks very much for your help.
The
formacro is lazy, so it will not invoke your function unless the return value is actually needed.Use the
doseqfunction instead. It will force the evaluation of your code, and thus is not lazy. It has the same “syntax” asforand allows you to account for side effecting functions such asprintln.