cgrand/enlive

deftemplate is side effect?

x86driver opened this issue · 2 comments

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?

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.

OK, Thanks.