IMO this is fairly absurd for a language default, but you can easily do this yourself in a number of ways. For example:
(defmacro define-preds [& preds] (cons `do (for [pred preds] `(defmacro ~(symbol (str pred "+")) ~'[obj then else] (list '~'if (list '~pred ~'obj) ~'then ~'else))))) (define-preds map? string?) (map?+ {} 1 2) ;; 1 This would be quite a lot easier if we didn't care about the short- circuiting behavior of 'if, since then a simple higher-order function would do it, something like (defn as-switch [pred] (fn [obj then else] (if (pred obj) then else))). On Apr 17, 9:16 pm, Dmitri <dmitri.sotni...@gmail.com> wrote: > Often times I find myself writing code like the following > > (if (map? foo) bar baz) > > would it make sense to make test functions variadic, so if only passed > a single argument it would return true/false, but could also act as an > if when passed 3 arguments, eg: > > (map? foo bar baz) would return bar if foo is a map and baz otherwise. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en