I understand that a do block will execute statements in sequence and return the value of the last one. I'd thought that if I didn't need the return value the do would be unnecessary. Not considering the return value, then, I don't understand the different behavior of these 2 functions:
with "do":
(defn x []
(if true
(do (println "a") (println "b"))))
=> (x)
a
b
nil
without "do":
(defn x []
(if true
((println "a") (println "b"))))
=> (x)
a
b
NullPointerException user/x (NO_SOURCE_FILE:3)
What is the cause of the NullPointer in the second example?
(if true [(println "a") (println "b")])
would do something substantially similar to what you're looking for (evaluating each element of the vector during its construction, thus enacting side effects); since this isn't function-call syntax, no null-pointer exception occurs.