fork download
  1. (defmacro bad-idea-double [x] `(+ ~x ~x))
  2.  
  3. (println (bad-idea-double 5))
  4.  
  5. (println "Let's see what happens when we use bad-idea-double with side-effects")
  6.  
  7. (println (bad-idea-double (do (println "A) doing side effects") 3)))
  8. ; How many times will "A) doing side effects" print?
  9.  
  10. (defmacro right-way-double [x] `(let [x-val# ~x] (+ x-val# x-val#)))
  11.  
  12. (println (right-way-double (do (println "B) doing side effects") 4)))
  13. ; How many times will "B) doing side effects" print?
  14.  
Success #stdin #stdout 1.19s 220224KB
stdin
Standard input is empty
stdout
10
Let's see what happens when we use bad-idea-double with side-effects
A) doing side effects
A) doing side effects
6
B) doing side effects
8