For that matter, I could do this: (defmacro andp ([] true) ([x p] `(~p ~x)) ([x p & next] `(let [and# (~p ~x)] (if and# (andp ~x ~...@next) and#))))
On Jul 23, 5:33 pm, ataggart <alex.tagg...@gmail.com> wrote: > Not that preserves the short-circuiting behavior of 'and. This works > though: > > (defmacro andf [& fns] > (let [x# (gensym)] > `(fn [~x#] (and ~@(map #(list % x#) fns))))) > > user=> (filter (andf integer? odd?) [1 2 3.1]) > (1) > > On Jul 23, 2:27 pm, ".Bill Smith" <william.m.sm...@gmail.com> wrote: > > > I want to filter a list based on the logical AND of a set of > > predicates. For example, let's say I have single-argument functions > > f, g, and h (without side-effects), and I want those items x in the > > list such that (f x), (g x) and (h x) are all true. I know I can do > > this: > > > (filter #(and (f %) (g %) (h %)) my-list) > > > Is there a more terse way to express the same thing? I suspect there > > is a mechanism similar to (or perhaps a generalization of) composition > > for that, but I couldn't find it in the API docs. > > > Bill Smith > > Austin, TX -- 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