Re: Quirk with filter

2009-08-19 Thread Christophe Grand
On Wed, Aug 19, 2009 at 2:33 AM, Sean Devlin wrote: > > The set is being passed in as a parameter, so that will be a problem. > Still, I'll be able to re-write my routine with false. Thanks! When the set is passed in as a parameter, one bulletproof[1] way to do that is: user=> (filter (partial

Re: Quirk with filter

2009-08-18 Thread CuppoJava
Hi Sean, I think your solution with (comp not nil? ... ) is very clean already. But in case you don't like that, here's another way of writing it: (filter #(contains? #{false} %) [false true false true]) returns (false false) It probably gets compiled to almost the same thing under the hood. But

Re: Quirk with filter

2009-08-18 Thread Mark Reid
Hi, The problem here is that filter is expecting a predicate and you are passing a set. When used as a function like so user=> (#{1 2 3} 2) 2 user=> (#{1 2 3} 5) nil the set returns the argument if it is in the set and nil otherwise. The problem you are observing is because the i

Re: Quirk with filter

2009-08-18 Thread Sean Devlin
The set is being passed in as a parameter, so that will be a problem. Still, I'll be able to re-write my routine with false. Thanks! On Aug 18, 8:18 pm, "J. McConnell" wrote: > On Tue, Aug 18, 2009 at 7:37 PM, Sean Devlin wrote: > > > > > user=> (filter #{false} [true false false true]) > > ()

Re: Quirk with filter

2009-08-18 Thread J. McConnell
On Tue, Aug 18, 2009 at 7:37 PM, Sean Devlin wrote: > > user=> (filter #{false} [true false false true]) > () > > Obviously, this is not what I intended. The best I could do was the > following > > user=> (filter (comp not nil? #{false}) [true false false true]) > (false false) > > Does anyone el

Quirk with filter

2009-08-18 Thread Sean Devlin
Hello Clojurians, I commonly use a set in my filtering operations, like the example below. user=> (filter #{\a \e \i \o \u} "The quick brown fox jumped over the lazy dog") (\e \u \i \o \o \u \e \o \e \e \a \o) Today I found myself using the following code user=> (filter #{false} [true false fal