deftemplate is side effect?
x86driver opened this issue · 2 comments
x86driver commented
Hi,
Is deftemplate with side effect?
For example,
(deftemplate xxx "public/temp.html" []
[:head :title] (let [r (rand-int 1000)] (prn r) (content (str r))))
I found (rand-int 1000)
will eval twice.
Do I understand it right?
cgrand commented
The expressions in a deftemplate are indeed evaluated at runtime and not at deftime. That's by design since expression usually depends on arguments or even application state.
x86driver commented
OK, Thanks.