On Nov 6, 12:10 pm, John Harrop <jharrop...@gmail.com> wrote:
> On Fri, Nov 6, 2009 at 1:07 PM, John Harrop <jharrop...@gmail.com> wrote:
> > On Fri, Nov 6, 2009 at 1:01 PM, Warren Wood
> > <warrenthomasw...@yahoo.com>wrote:
>
> >> In the meantime, I came up with the following, which seems to work.
> >> I'm sure it can be improved.
>
> >> (defn NOT [pred] (fn [x] (not (pred x))))
>
> >> ...
>
> > Which leads me to another question, are there standard functions
> >> sitting around somewhere already to do boolean combinations of
> >> predicates (conjoin, disjoin, negate perhaps?)? Like my NOT above.
>
> > How about complement?
>
> > user=> (def x (complement even?))
> > #'user/x
> > user=> (x 4)
> > false
> > user=> (x 3)
> > true
>
> And WHAT the devil is with complement's messy implementation? (defn
> complement [f] (comp not f)) seems much cleaner. :)
Ok, I'm embarrassed that I didn't find complement. I know I had known
about it at one time. I think I had been wondering about versions of
union and intersection that would apply to predicates as well as sets,
since mathematically a predicate can be deemed as defining the set of
all things for which it is true. I was thinking of a procedure like
AND (again probably not a great name... maybe conjunction would be
better). I don't think anything like comp can be used in this case
since and is a macro.
(defn AND [f g] (fn [x] (and (f x) (g x))))
Is there any standard function like THAT?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---