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

0 votes
in Syntax and reader by
edited by


Hi. As I'm learning clojure, I decided to draw a expression tree for my factorial code.

However, It seems like using (2) defn or (1) def and fn doesn't generate a nice looking expression tree.

So I've come up with (3) mydef which reveals the structure of a function and its argument. Drawn in the form of expression tree, this makes sense.

My question is:
1) Does (1) and (2) actually makes more sense?
2) is there a reason that function definition is not written like (3) mydef?

Here is the link to the diagram if anyone wants to use it:

1 Answer

0 votes

Clojure supports defining multiple arities in the same function definition btw, like:

(defn foo
   ([] "hi")
   ([x] (str "hi " x)))

defn is a special form but implemented as a macro that is basically defining a custom syntax. I'm not sure there is any way to win "best syntax" - that's why we have 100s of programming languages. :)