In clojure, I would like to write a defn-my macro that creates a function with a body. And when this function is executed, it exits on first statement that doesn’t return 0.
For example:
(defn f1[] (println "f1") 5)
(defn f2[] (println "f2") 0)
(defn-my foo[] (f1) (f2))
(defn-my bar[] (f2) (f1))
(foo); should execute f1 and exit
(bar); should execute f2 and then f1
I think you are asking for something like this:
The macro assumes every expression evaluates to a number. It will throw an exception if, for example, an expression evaluates to
nil.Then you can write yout
defn-mylike this: