(defmacro cond-let
([] nil)
([x] (throw (IllegalArgumentException. "cond-let error: last one form")))
([a b] (list 'if a b nil))
([a b c & forms]
(if (vector? a)
(list 'let a (list 'if b c (cons 'cond-let forms)))
(list 'if a b (cons 'cond-let (cons c forms)))
)))
(defn tst [m]
(cond-let
[a (:a m)]
(not a) "not a"
[b (+ 1 a)
c (* 10 b)]
(< c 50) "too small c"
(= c 50) "exact c"
[d (str "a = " a ", b = " b ", c = " c)
e (count d)]
:else {:text d, :length e}))
(println (tst {}))
(doseq [x '(1 4 5)] (println (tst {:a x})))
KGRlZm1hY3JvIGNvbmQtbGV0CiAgKFtdIG5pbCkKICAoW3hdICh0aHJvdyAoSWxsZWdhbEFyZ3VtZW50RXhjZXB0aW9uLiAiY29uZC1sZXQgZXJyb3I6IGxhc3Qgb25lIGZvcm0iKSkpCiAgKFthIGJdIChsaXN0ICdpZiBhIGIgbmlsKSkKICAoW2EgYiBjICYgZm9ybXNdCiAgIChpZiAodmVjdG9yPyBhKQogICAgIChsaXN0ICdsZXQgYSAgIChsaXN0ICdpZiBiIGMgKGNvbnMgJ2NvbmQtbGV0IGZvcm1zKSkpCiAgICAgKGxpc3QgJ2lmICBhIGIgKGNvbnMgJ2NvbmQtbGV0IChjb25zIGMgZm9ybXMpKSkKICAgICApKSkKCihkZWZuIHRzdCBbbV0KICAoY29uZC1sZXQKICAgIFthICg6YSBtKV0KICAgIChub3QgYSkgIm5vdCBhIgogICAgW2IgKCsgMSBhKQogICAgIGMgKCogMTAgYildCiAgICAoPCBjIDUwKSAidG9vIHNtYWxsIGMiCiAgICAoPSBjIDUwKSAiZXhhY3QgYyIKICAgIFtkIChzdHIgImEgPSAiIGEgIiwgYiA9ICIgYiAiLCBjID0gIiBjKQogICAgIGUgKGNvdW50IGQpXQogICAgOmVsc2Ugezp0ZXh0IGQsIDpsZW5ndGggZX0pKQoKKHByaW50bG4gKHRzdCB7fSkpCihkb3NlcSBbeCAnKDEgNCA1KV0gKHByaW50bG4gKHRzdCB7OmEgeH0pKSkK