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

+1 vote
in Macros by

I feel like with pair of macros if and cond we miss companion macro for if-let:

(defmacro cond-let
  [& clauses]
  (when clauses
    (if (next clauses)
      (list 'if-let (first clauses)
            (second clauses)
            (cons 'cond-let (nnext clauses)))
      (first clauses))))

(cond-let [a nil] {:a a}
          [b false] {:b b}
          :default)

I did not find if this variation of cond-let (without introducing much new syntax) macro were discussed in the past but generally it looks like natural for clolure.core.

1 Answer

0 votes
by

When would you use it?

by
I worked with code having multiple nested `if-let` and found this pattern.
```
(if-let [a ...]
  (do a)
  (if-let [b ...]
    (do b)
    (do :default))
```
Later I realized that this rare situation and such macro is not very useful.
Sorry for disturbance.
Let's forget about this incident :-)
...