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

0 votes
in Syntax and reader by
edited by

https://imgur.com/a/X11sBxI

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:
https://drive.google.com/file/d/1hUnifN8GM5wGr9r8lE1jgCPqU4zH8iYE/view?usp=sharing

1 Answer

0 votes
by

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. :)

...