Skip to content

Instantly share code, notes, and snippets.

;;before compilation
(defmacro ifWorkday [bigCalc1, bigCalc2]
`(if (workday (today))
~bigCalc1
~bigCalc2))
;; the call
(ifWorkday (+ 1 1) (otherBigCalc))
;;... after compilation...
;; nothing gets evaluated inside the list at all..
‘(a b c)
(= a a)
;; => java.lang.Exception: Unable to resolve symbol: a in this context
(= ‘a ‘a)
;;=> true
‘(a b c d)
;;=> (a b c d)
#if it is a macro...
defmacro ifworkday(first, second)
if workday(today()) do
return first
else
return second
end
end
ifworkday(1+1, doOtherHugeCalc())
def ifworkday(first, second)
if workday(today()) do
return first
else
return second
end
end
x = ifworkday(1 + 1, doOtherHugeCalc())
#when the values are “shown”
if workday(today()) do
x = 1 + 1
else
x = doOtherHugeCalc()
end
;; example up from clouredocs.org:
;; http://clojuredocs.org/clojure_contrib/clojure.contrib.trace/deftrace
(deftrace fib [n]
(if (or (= n 0) (= n 1))
1
(+ (fib (- n 1)) (fib (- n 2)))))
(fib 4)
;; => 5
;; 1> TRACE t2742: (fib 4)
;; trace-forms "Trace all the forms in the given body. Returns any
;; underlying uncaught exceptions that may make the forms fail."
(trace-forms
(let [a (+ 1 1)
b (* 2 2)
c (* a b (/ 4 0))]
c))
;; => ArithmeticException Divide by zero
;; Form failed: (/ 4 0)
;; Form failed: (* a b (/ 4 0))