Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in Macros by

Why doesn't defn implicitly name the function to create a named recursion point?


(clojure.walk/macroexpand-all
'(defn foo [x] (foo x)))

; =>
(def foo
(fn*

([x]
 (foo x))))


This could instead expand to


(def foo
(fn* foo ; note the foo here ([x] (foo x))))


which should, in case of the recursive call, compile to a direct call to the function object without the need to dereference the var at runtime.

Please log in or register to answer this question.

...