Not as a macro I hope. You lose apply.
On Jan 21, 3:49 pm, Richard Newman <holyg...@gmail.com> wrote: > > I think it's easier to think about combining predicates separately > > from your file-filtering code. I'd use a higher-order function like > > the following > > > (defn combine-preds > > [& preds] > > (fn [& args] (every? #(apply % args) preds))) > > I've noticed that most uses of this kind of thing are for fixed sets > of predicates, and almost always for two, so I'd define: > > (defmacro both [p1 p2] > `(fn [& args#] > (and (apply ~p1 args#) > (apply ~p2 args#)))) > > Which reads nicely: > > (filter (both number? even?) (range 1 7)) > > and is probably more efficient (not that I've tested it). > > You can generalize this to `all`, of course.
-- 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