fork download
  1. (defmacro cond-let
  2. ([] nil)
  3. ([x] (throw (IllegalArgumentException. "cond-let error: last one form")))
  4. ([a b] (list 'if a b nil))
  5. ([a b c & forms]
  6. (if (vector? a)
  7. (list 'let a (list 'if b c (cons 'cond-let forms)))
  8. (list 'if a b (cons 'cond-let (cons c forms)))
  9. )))
  10.  
  11. (defn tst [m]
  12. (cond-let
  13. [a (:a m)]
  14. (not a) "not a"
  15. [b (+ 1 a)
  16. c (* 10 b)]
  17. (< c 50) "too small c"
  18. (= c 50) "exact c"
  19. [d (str "a = " a ", b = " b ", c = " c)
  20. e (count d)]
  21. :else {:text d, :length e}))
  22.  
  23. (println (tst {}))
  24. (doseq [x '(1 4 5)] (println (tst {:a x})))
  25.  
Success #stdin #stdout 1.1s 4386816KB
stdin
Standard input is empty
stdout
not a
too small c
exact c
{:text a = 5, b = 6, c = 60, :length 20}