Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
conjoin and disjoin for core or contrib?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  22 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Fogus  
View profile  
 More options Jan 24 2011, 10:35 am
From: Fogus <mefo...@gmail.com>
Date: Mon, 24 Jan 2011 07:35:48 -0800 (PST)
Local: Mon, Jan 24 2011 10:35 am
Subject: conjoin and disjoin for core or contrib?
I've recently come across a need for conjoin and disjoin functions
implemented[1] as follows:

(defn conjoin
  "Given a bunch of predicates, returns a function that is the logical
AND
   of said functions against a bunch of values."
  [& preds]
  (fn [& args]
    (every? (fn [arg]
              (every? #(% arg)
                      preds))
            args)))

(defn disjoin
  "Given a bunch of predicates, returns a function that is the logical
OR
   of said functions against a bunch of values."
  [& preds]
  (fn [& args]
    (some (fn [arg]
            (some #(% arg)
                  preds))
          args)))

I might have lost my mind, but neither of these functions appear to
exist in core or contrib and I thought it might be worth floating them
out for general consumption to see if they might be useful inclusions
in one or the other.  The problem in the case of contrib is that it's
unclear where they would fit.

Thanks.

[1]: Nicer formatting and examples at https://gist.github.com/790187


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Baishampayan Ghose  
View profile  
 More options Jan 24 2011, 10:42 am
From: Baishampayan Ghose <b.gh...@gmail.com>
Date: Mon, 24 Jan 2011 21:12:45 +0530
Local: Mon, Jan 24 2011 10:42 am
Subject: Re: conjoin and disjoin for core or contrib?

As a side effect of conjoin using every? and disjoin using some,
disjoin returns nil and disjoin returns false in cases when the
conditions fail.

Is that a good idea? Does renaming disjoin to disjoin? make any sense?

Regards,
BG

--
Baishampayan Ghose
b.ghose at gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Balthrop  
View profile  
 More options Jan 24 2011, 11:00 am
From: Justin Balthrop <jus...@justinbalthrop.com>
Date: Mon, 24 Jan 2011 08:00:49 -0800
Local: Mon, Jan 24 2011 11:00 am
Subject: Re: conjoin and disjoin for core or contrib?
I have similar functions named 'any' and 'all' in my utils library. I think having them in core makes sense.

Both return functions, so it doesn't make sense for disjoin/any to end in ?

On Jan 24, 2011, at 7:35 AM, Fogus <mefo...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christophe Grand  
View profile  
 More options Jan 24 2011, 11:45 am
From: Christophe Grand <christo...@cgrand.net>
Date: Mon, 24 Jan 2011 17:45:11 +0100
Local: Mon, Jan 24 2011 11:45 am
Subject: Re: conjoin and disjoin for core or contrib?

Hi,

I'm not a huge fan of varargs here since in most code where I needed this
kind of functinality I already had collections.

As a side note, you can simplify this kind of code by inverting args and
preds walks:
(defn conjoin [& preds]
  (fn [& args] (every? #(every? % args) preds)))

(defn disjoin [& preds]
  (fn [& args] (some #(some % args) preds)))

Christophe

On Mon, Jan 24, 2011 at 5:00 PM, Justin Balthrop
<jus...@justinbalthrop.com>wrote:

--
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Devlin  
View profile  
 More options Jan 24 2011, 12:23 pm
From: Sean Devlin <francoisdev...@gmail.com>
Date: Mon, 24 Jan 2011 12:23:44 -0500
Local: Mon, Jan 24 2011 12:23 pm
Subject: Re: conjoin and disjoin for core or contrib?

I have a version very similar to Christophe's code in my libs.  +1 for core.

On Mon, Jan 24, 2011 at 11:45 AM, Christophe Grand <christo...@cgrand.net>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fogus  
View profile  
 More options Jan 24 2011, 12:19 pm
From: Fogus <mefo...@gmail.com>
Date: Mon, 24 Jan 2011 09:19:35 -0800 (PST)
Local: Mon, Jan 24 2011 12:19 pm
Subject: Re: conjoin and disjoin for core or contrib?

> As a side note, you can simplify this kind of code by inverting args and
> preds walks

Thank you.  I should have had to look over my work before
posting.  :-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan  
View profile  
 More options Jan 24 2011, 1:29 pm
From: Alan <a...@malloys.org>
Date: Mon, 24 Jan 2011 10:29:37 -0800 (PST)
Local: Mon, Jan 24 2011 1:29 pm
Subject: Re: conjoin and disjoin for core or contrib?
Seconded. I was actually about to put a request for these on JIRA when
I found Fogus's request here.

On Jan 24, 8:00 am, Justin Balthrop <jus...@justinbalthrop.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Faulhaber  
View profile  
 More options Jan 24 2011, 5:17 pm
From: Tom Faulhaber <tomfaulha...@gmail.com>
Date: Mon, 24 Jan 2011 14:17:21 -0800
Local: Mon, Jan 24 2011 5:17 pm
Subject: Re: conjoin and disjoin for core or contrib?

I'll chime in here as well: I've been using conjoin a lot in some code I've
been doing to analyze bug databases.

So: +1


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Miner  
View profile  
 More options Jan 24 2011, 6:31 pm
From: Steve Miner <stevemi...@gmail.com>
Date: Mon, 24 Jan 2011 18:31:08 -0500
Local: Mon, Jan 24 2011 6:31 pm
Subject: Re: conjoin and disjoin for core or contrib?
I like Christophe's implementations. I agree that the proposed functions would be useful. It's probably good to spend a release cycle in contrib. You could start a higher-order functions section for contrib. As an aside, I think it's important that we keep new users in mind when adding functions to core.  Lots of useful functions are outside of core (such as the set functions), and I don't feel that the proposed methods need to be in core right away.

I'm concerned about the proposed names being confused with conj and disj (especially by new users.) In particular, the doc strings say that they're short for conj[oin] and disj[oin].   'any' and 'all' might be better.  Although, confusion with 'any?' could also be an issue.  That's another reason to go with contrib for the first release.

Clojure already has comp and juxt, which follow this pattern of taking var-args of functions.  That part seems OK to me.

Regards,
Steve Miner

On Jan 24, 2011, at 11:45 AM, Christophe Grand wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Laurent PETIT  
View profile  
 More options Jan 24 2011, 6:36 pm
From: Laurent PETIT <laurent.pe...@gmail.com>
Date: Tue, 25 Jan 2011 00:36:25 +0100
Local: Mon, Jan 24 2011 6:36 pm
Subject: Re: conjoin and disjoin for core or contrib?
If the final target would be clojure.core, then clojure.contrib.core
would be an ideal candidate ?

2011/1/25 Steve Miner <stevemi...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Devlin  
View profile  
 More options Jan 24 2011, 6:41 pm
From: Sean Devlin <francoisdev...@gmail.com>
Date: Mon, 24 Jan 2011 18:41:56 -0500
Local: Mon, Jan 24 2011 6:41 pm
Subject: Re: conjoin and disjoin for core or contrib?

I named my versions any-pred & every-pred, fwiw.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cosmin Stejerean  
View profile  
 More options Jan 24 2011, 9:02 pm
From: Cosmin Stejerean <cos...@offbytwo.com>
Date: Mon, 24 Jan 2011 20:02:50 -0600
Local: Mon, Jan 24 2011 9:02 pm
Subject: Re: conjoin and disjoin for core or contrib?

On Mon, Jan 24, 2011 at 5:41 PM, Sean Devlin <francoisdev...@gmail.com>wrote:

> I named my versions any-pred & every-pred, fwiw.

+1 for any-pred and every-pred instead of conjoin and disjoin.

--
Cosmin Stejerean
http://offbytwo.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Miller  
View profile  
 More options Jan 24 2011, 10:52 pm
From: Alex Miller <alexdmil...@yahoo.com>
Date: Mon, 24 Jan 2011 19:52:58 -0800 (PST)
Local: Mon, Jan 24 2011 10:52 pm
Subject: Re: conjoin and disjoin for core or contrib?

I needed these just last week!  +1

I concur in disliking conjoin and disjoin although I don't have a strong
preference for any of the alternatives mentioned.  any and all/every seem like
better words.  

________________________________
From: Cosmin Stejerean <cos...@offbytwo.com>
To: clojure-dev@googlegroups.com
Sent: Mon, January 24, 2011 8:02:50 PM
Subject: Re: conjoin and disjoin for core or contrib?

On Mon, Jan 24, 2011 at 5:41 PM, Sean Devlin <francoisdev...@gmail.com> wrote:

I named my versions any-pred & every-pred, fwiw.
+1 for any-pred and every-pred instead of conjoin and disjoin.

--
Cosmin Stejerean
http://offbytwo.com

--
You received this message because you are subscribed to the Google Groups
"Clojure Dev" group.
To post to this group, send email to clojure-dev@googlegroups.com.
To unsubscribe from this group, send email to
clojure-dev+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/clojure-dev?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert McIntyre  
View profile  
 More options Jan 24 2011, 11:30 pm
From: Robert McIntyre <r...@mit.edu>
Date: Mon, 24 Jan 2011 23:30:47 -0500
Local: Mon, Jan 24 2011 11:30 pm
Subject: Re: conjoin and disjoin for core or contrib?
How about clojure.contrib.function-utils for a possible target in contrib?

--Robert McIntyre


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fogus  
View profile  
 More options Jan 25 2011, 8:04 am
From: Fogus <mefo...@gmail.com>
Date: Tue, 25 Jan 2011 05:04:28 -0800 (PST)
Local: Tues, Jan 25 2011 8:04 am
Subject: Re: conjoin and disjoin for core or contrib?
So it seems that there is some interest in the following:

- Contribify these functions
- ... in a new contrib module (functional, combinators, fun, other?)
- ... with different names (any/every-pred, other?)
- ... and (possibly) include other similar functions

I'm happy to spear-head setting this up if Clojure/core is interested.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rich Hickey  
View profile  
 More options Jan 26 2011, 8:09 am
From: Rich Hickey <richhic...@gmail.com>
Date: Wed, 26 Jan 2011 08:09:11 -0500
Local: Wed, Jan 26 2011 8:09 am
Subject: Re: conjoin and disjoin for core or contrib?

On Jan 25, 2011, at 8:04 AM, Fogus wrote:

> So it seems that there is some interest in the following:

> - Contribify these functions
> - ... in a new contrib module (functional, combinators, fun, other?)
> - ... with different names (any/every-pred, other?)
> - ... and (possibly) include other similar functions

> I'm happy to spear-head setting this up if Clojure/core is interested.

I'll take them in core as every-pred and any-pred, but you'll have to  
do the variadic unrolling as per comp and juxt. Extra credit for a  
macro that eliminates the tedium of such unrolling and works for comp,  
juxt et al.

Thanks,

Rich


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart Halloway  
View profile   Translate to Translated (View Original)
 More options Jan 28 2011, 11:09 am
From: Stuart Halloway <stuart.hallo...@gmail.com>
Date: Fri, 28 Jan 2011 11:09:33 -0500
Local: Fri, Jan 28 2011 11:09 am
Subject: Re: conjoin and disjoin for core or contrib?

> So it seems that there is some interest in the following:

> - Contribify these functions
> - ... in a new contrib module (functional, combinators, fun, other?)
> - ... with different names (any/every-pred, other?)
> - ... and (possibly) include other similar functions

> I'm happy to spear-head setting this up if Clojure/core is interested.

> --
> You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
> To post to this group, send email to clojure-dev@googlegroups.com.
> To unsubscribe from this group, send email to clojure-dev+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.

Thanks for the work on this, Fogus! The patch needs a small fix, and maybe some discussion about the name "some" vs. "any". I would like to get this in today, if anybody has time to respond to questions at http://dev.clojure.org/jira/browse/CLJ-729.

Stu

Stuart Halloway
Clojure/core
http://clojure.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Devlin  
View profile  
 More options Jan 28 2011, 12:29 pm
From: Sean Devlin <francoisdev...@gmail.com>
Date: Fri, 28 Jan 2011 12:29:10 -0500
Local: Fri, Jan 28 2011 12:29 pm
Subject: Re: conjoin and disjoin for core or contrib?

I agree with you comments about the boolean behavior of every-pred.

I've also deliberately named my version of any-pred that way, because it
return a boolean.  Of course, I also think there should be a any? fn in core
as well, so YMMV.

I'd add one more expression to each fn, like so

(defn every-pred [& preds]
  (fn [& args] (if (every? #(every? % args) preds)) true false)))

(defn any-pred [& preds]
  (fn [& args] (if (some #(some % args) preds)) true false))

My $.02

Sean

On Fri, Jan 28, 2011 at 11:09 AM, Stuart Halloway <stuart.hallo...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Stadig  
View profile  
 More options Jan 28 2011, 2:16 pm
From: Paul Stadig <p...@stadig.name>
Date: Fri, 28 Jan 2011 14:16:41 -0500
Local: Fri, Jan 28 2011 2:16 pm
Subject: Re: conjoin and disjoin for core or contrib?

Perhaps it all depends upon your application, but the original version is
better for lazy seqs. With Christophe's version this will never return

(apply (conjoin pos? even?) (iterate inc 1))

Paul

On Mon, Jan 24, 2011 at 11:45 AM, Christophe Grand <christo...@cgrand.net>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Devlin  
View profile  
 More options Jan 28 2011, 2:25 pm
From: Sean Devlin <francoisdev...@gmail.com>
Date: Fri, 28 Jan 2011 14:25:22 -0500
Local: Fri, Jan 28 2011 2:25 pm
Subject: Re: conjoin and disjoin for core or contrib?

Yeah, that's an "oops"  Chistophe + Binary return is what I meant.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Teuber  
View profile   Translate to Translated (View Original)
 More options Feb 5 2011, 5:06 am
From: Benjamin Teuber <bsteu...@googlemail.com>
Date: Sat, 5 Feb 2011 02:06:11 -0800 (PST)
Local: Sat, Feb 5 2011 5:06 am
Subject: Re: conjoin and disjoin for core or contrib?
Also needed these function this week - but I called them and? and or?.
Not sure if it's best to use ? as suffix for higher-order predicates,
but I've added a bunch more and it seems quite readable to me:

((and? sequential?
       (first? odd?)
       (second? (=? 42)))
 [5 42])

=> true


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan  
View profile  
 More options Feb 7 2011, 12:42 pm
From: Alan <a...@malloys.org>
Date: Mon, 7 Feb 2011 09:42:20 -0800 (PST)
Local: Mon, Feb 7 2011 12:42 pm
Subject: Re: conjoin and disjoin for core or contrib?
I don't see the value in your additional predicates, and they're not
super-easy to read, either. Given that and? exists, I would write the
below as:

((and? sequential?
       (comp odd? first)
       (comp #{42} second)
  [5 42])

On Feb 5, 2:06 am, Benjamin Teuber <bsteu...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »