Thought of this, which I like better. Again, I'm surprised if
conjunction is not already a standard function, but I can't find it.
I'm still a bit tempted to call it AND for readabilty of code. (I
spent some time studying combinatory logic back in the day. (I even
had a "Curry Fellowship" at Penn State where Haskell Curry used to
work.) Can't remember what combinator letter my "dual" function is.)
(defn dual [x] (fn [f] (f x)))
(defn conjunction [& preds]
(fn [x] (every? (dual x) preds)))
(filter
(conjunction even? (partial >= 16) (partial <= 9))
(range 1 20))
evaluates to
(10 12 14 16)
On Nov 7, 9:39 pm, Warren Wood <[email protected]> wrote:
> On Nov 6, 12:10 pm, John Harrop <[email protected]> wrote:
>
>
>
>
>
> > On Fri, Nov 6, 2009 at 1:07 PM, John Harrop <[email protected]> wrote:
> > > On Fri, Nov 6, 2009 at 1:01 PM, Warren Wood
> > > <[email protected]>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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---