Re: contains? on String

2015-05-13 Thread Erik Price
> (get "the char at index" 4) \c e ​ On Wed, May 13, 2015 at 9:55 PM, Sam Raker wrote: > I always assumed (contains? "foo" 2) worked because strings are arrays > (i.e. vectors) of characters, on some level. > > -- > You received this message because you are subscribed to the Google > Groups "C

Re: contains? on String

2015-05-13 Thread Sam Raker
I always assumed (contains? "foo" 2) worked because strings are arrays (i.e. vectors) of characters, on some level. -- 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 n

Re: contains? on String

2015-05-12 Thread Fluid Dynamics
On Tuesday, May 12, 2015 at 5:05:00 PM UTC-4, Michael Gardner wrote: > > On May 12, 2015, at 3:28 PM, Fluid Dynamics > wrote: > > Strings and arrays support constant-time access by index. > > Yes, but why should that mean that contains? should work on Strings? > "Because it can" doesn't seem co

Re: contains? on String

2015-05-12 Thread Devin Walters
Ignoring some of the conversation here to point out that what you want is: (.contains "foo" "f") On Tue, May 12, 2015 at 4:04 PM, Michael Gardner wrote: > On May 12, 2015, at 3:28 PM, Fluid Dynamics wrote: > > Strings and arrays support constant-time access by index. > > Yes, but why should tha

Re: contains? on String

2015-05-12 Thread Michael Gardner
On May 12, 2015, at 3:28 PM, Fluid Dynamics wrote: > Strings and arrays support constant-time access by index. Yes, but why should that mean that contains? should work on Strings? "Because it can" doesn't seem compelling to me. In discussions about contains?, one often hears that it works on as

Re: contains? on String

2015-05-12 Thread Lee Spector
> On May 12, 2015, at 4:28 PM, Fluid Dynamics wrote: > > On Tuesday, May 12, 2015 at 3:34:46 PM UTC-4, Michael Gardner wrote: > On May 12, 2015, at 1:54 PM, Shantanu Kumar > wrote: > > I agree about the counter-intuitiveness. I'm only wondering whether the > > error message is a bit misleadin

Re: contains? on String

2015-05-12 Thread Fluid Dynamics
On Tuesday, May 12, 2015 at 3:34:46 PM UTC-4, Michael Gardner wrote: > > On May 12, 2015, at 1:54 PM, Shantanu Kumar > wrote: > > I agree about the counter-intuitiveness. I'm only wondering whether the > error message is a bit misleading "contains? not supported on type: > java.lang.String" bec

Re: contains? on String

2015-05-12 Thread Michael Gardner
On May 12, 2015, at 1:54 PM, Shantanu Kumar wrote: > I agree about the counter-intuitiveness. I'm only wondering whether the error > message is a bit misleading "contains? not supported on type: > java.lang.String" because of course (contains? "hello" 2) works fine. It seems odd that (contains?

Re: contains? on String

2015-05-12 Thread James Reeves
On 12 May 2015 at 19:54, Shantanu Kumar wrote: > I agree about the counter-intuitiveness. I'm only wondering whether the > error message is a bit misleading "contains? not supported on type: > java.lang.String" because of course (contains? "hello" 2) works fine. > Oh, I see! Yes, that is a bit m

Re: contains? on String

2015-05-12 Thread Shantanu Kumar
I agree about the counter-intuitiveness. I'm only wondering whether the error message is a bit misleading "contains? not supported on type: java.lang.String" because of course (contains? "hello" 2) works fine. Shantanu On Wednesday, 13 May 2015 00:12:19 UTC+5:30, James Reeves wrote: > > contain

Re: contains? on String

2015-05-12 Thread James Reeves
contains? has always been a little counter-intuitive. It essentially only works on collections that allow for a constant or logarithmic lookup time, and often works on the "keys" of a collection, rather than its values. The only exception to this are sets, where the values are essentially keys as w

Re: contains? and transient set

2013-12-04 Thread Alex Miller
It is not currently in the list for 1.6. At some point, we have to draw a line and bear down on some set of tickets - this ticket is currently behind that line. We will be more regularly moving patches through the system, getting them reviewed and included in master, and releasing new versions

Re: contains? and transient set

2013-12-04 Thread László Török
cool! hope the patch is good for 1.6! :) 2013/12/4 Alex Miller > Both contains? and get should work with transient sets imo. > > This is already in jira: http://dev.clojure.org/jira/browse/CLJ-700. > > Alex > > On Wednesday, December 4, 2013 5:04:40 AM UTC-6, Burt wrote: >> >> Does contains? an

Re: contains? and transient set

2013-12-04 Thread Ben Wolfson
This is not a good way to check whether an *arbitrary* element is in a set: user=> (contains? #{nil} nil) true user=> (#{nil} nil) nil On Wed, Dec 4, 2013 at 3:35 AM, László Török wrote: > Hi, > > contains? is for checking whether a data structure contains the respective > key. > > A more idi

Re: contains? and transient set

2013-12-04 Thread Alex Miller
Both contains? and get should work with transient sets imo. This is already in jira: http://dev.clojure.org/jira/browse/CLJ-700. Alex On Wednesday, December 4, 2013 5:04:40 AM UTC-6, Burt wrote: > > Does contains? and get not work with transient sets? > > Examples: > (contains? #{1 2 3} 1) > ;

Re: contains? and transient set

2013-12-04 Thread Burt
Hi Stefan, I did not search in Jira, I don't know whether this is a known bug. I use the Lars' work-around in the context I need contains? with a transient set. Regards, Burt Am Mittwoch, 4. Dezember 2013 14:29:35 UTC+1 schrieb Stefan Kamphausen: > > It looks like you're onto something here >

Re: contains? and transient set

2013-12-04 Thread Max Penet
Well not quite: > (contains? (transient #{1 2 3}) 1) false > *clojure-version* {:major 1, :minor 4, :incremental 0, :qualifier nil} > So it used not to throw but return a wrong value instead, which was worse. On Wednesday, December 4, 2013 2:50:19 PM UTC+1, Max Penet wrote: > > Also it seems

Re: contains? and transient set

2013-12-04 Thread Max Penet
Also it seems it used to work on clojure 1.4 On Wednesday, December 4, 2013 2:29:35 PM UTC+1, Stefan Kamphausen wrote: > > It looks like you're onto something here > > get works with transient maps: > > (get (transient {:a 1 :b 2}) :a) > ;=> 1 > > and with transient vectors, too: > > (get (transie

Re: contains? and transient set

2013-12-04 Thread Stefan Kamphausen
It looks like you're onto something here get works with transient maps: (get (transient {:a 1 :b 2}) :a) ;=> 1 and with transient vectors, too: (get (transient [1 2 3]) 0) ;=> 1 but not with transient sets: (get (transient #{1 2 3}) 2) ;=> nil And using contains? in a reduce with a transient

Re: contains? and transient set

2013-12-04 Thread Burt
Thanks, Burt > > -- -- 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 g

Re: contains? and transient set

2013-12-04 Thread László Török
Hi, contains? is for checking whether a data structure contains the respective key. A more idiomatic way to check whether an element is in the set is (#{1 2 3} 1) ;; => returns 1 (#{1 2 3} 0) ;; => returns nil works for (transient #{1 2 3}) too. Las 2013/12/4 Burt > Does contains? and g

Re: contains? for vectors

2013-03-01 Thread AtKaaZ
and obviously I would like it to throw here instead :) but hey, that's just me - overly obsessed with fail-fast rather that performance first or tolerance On Fri, Mar 1, 2013 at 9:12 PM, AtKaaZ wrote: > user=> (contains? "abc" 1.5) > true > > looks like for that, it's coerced to int > > else if

Re: contains? for vectors

2013-03-01 Thread AtKaaZ
user=> (contains? "abc" 1.5) true looks like for that, it's coerced to int else if(key instanceof Number && (coll instanceof String || coll.getClass().isArray())) { int n = ((Number) key).intValue(); return n >= 0 && n < count(coll); } => (int 1.4) 1 => (int 1.6) 1 => (.intVal

Re: contains? for vectors

2013-03-01 Thread AtKaaZ
Right, but I'm only after the when-invalid-key is passed: valid: => (contains? "abc" 1) true => (contains? ["a" "b" "c"] 1) true invalid: => (contains? "abc" "a") IllegalArgumentException contains? not supported on type: java.lang.String clojure.lang.RT.contains (RT.java:724) => (contains? ["a" "b

Re: contains? for vectors

2013-03-01 Thread Michael Gardner
On Mar 1, 2013, at 13:36 , AtKaaZ wrote: > I don't think I understand what you mean (could you rephrase/example?), I > cannot think of a case when I wouldn't want it to throw when I'm passing a > non-number (contains? [:a :b :c] :a), I mean, rather than just silently > ignoring. I'm talking a

Re: contains? for vectors

2013-03-01 Thread Maik Schünemann
the old contails? debate :) contains? is only intented for associative collections. This explains (somewhat) the behavior on vectors. They are seen as assocuative collections from indexes to values. I'm not exactly sure about this, but I expect (contains? c x) to be true if you can call (get c x).

Re: contains? for vectors

2013-03-01 Thread AtKaaZ
I don't think I understand what you mean (could you rephrase/example?), I cannot think of a case when I wouldn't want it to throw when I'm passing a non-number (contains? [:a :b :c] :a), I mean, rather than just silently ignoring. It;s not unlike this: => (contains? '(:a :b :c) :a) IllegalArgumentE

Re: contains? for vectors

2013-03-01 Thread Michael Gardner
On Feb 28, 2013, at 17:17 , AtKaaZ wrote: > According to this, can a vector have keys that are not numbers? like :a , if > not, then wouldn't it make more sense that > (contains? [:a :b :c] :a) would throw ? It's probably just me. This is a reasonable point, and one I haven't seen made before.

Re: contains? for vectors

2013-02-28 Thread Tassilo Horn
Irakli Gozalishvili writes: > Maybe something else can be considered like `includes?` to do that > instead ? Also Rich says no better name was suggest for includes?, I > think `has?` would have being a lot better name. Don't know if it > makes sense to reply to that post at this point. I think

Re: contains? for vectors

2013-02-28 Thread Irakli Gozalishvili
Thanks Michael, This links are helpful. As far as I can see nothing like contains-val? or seq-contains? has being added though :( I'm trying to use cljs for performance sensitive code and high order functions like `some` don't really do it, while indexOf on strings in JS are well optimised by en

Re: contains? for vectors

2013-02-28 Thread AtKaaZ
On Thu, Feb 28, 2013 at 11:59 PM, Michael Gardner wrote: > This is a sore spot that has been discussed many times on this list[1]. > The short version is that many people agree that the name "contains?" is > misleading to newcomers, but according to Rich it's not changing any time > soon[2]. What

Re: contains? for vectors

2013-02-28 Thread Michael Gardner
This is a sore spot that has been discussed many times on this list[1]. The short version is that many people agree that the name "contains?" is misleading to newcomers, but according to Rich it's not changing any time soon[2]. What you want for linear searches is 'some (as mentioned in the doc

Re: contains? for vectors

2013-02-28 Thread AtKaaZ
by errors I mean bugs On Thu, Feb 28, 2013 at 11:43 PM, AtKaaZ wrote: > > > > On Thu, Feb 28, 2013 at 11:23 PM, AtKaaZ wrote: > >> => *(contains? '(1 2 3) 1)* >> IllegalArgumentException contains? not supported on type: >> clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) >>

Re: contains? for vectors

2013-02-28 Thread AtKaaZ
On Thu, Feb 28, 2013 at 11:23 PM, AtKaaZ wrote: > => *(contains? '(1 2 3) 1)* > IllegalArgumentException contains? not supported on type: > clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) > > => **clojure-version** > {:major 1, :minor 5, :incremental 0, :qualifier "RC17"} > >

Re: contains? for vectors

2013-02-28 Thread AtKaaZ
=> *(contains? '(1 2 3) 1)* IllegalArgumentException contains? not supported on type: clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) => **clojure-version** {:major 1, :minor 5, :incremental 0, :qualifier "RC17"} => *(contains? "foo" "o")* IllegalArgumentException contains? n

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-25 Thread mnicky
Wow. Thanks, Cedric. I'll definitely look into those options... On Sunday, March 25, 2012 4:28:04 AM UTC+2, Cedric Greevey wrote: > > On Sat, Mar 24, 2012 at 9:39 PM, Cedric Greevey > wrote: > > In increasing order of difficulty... > > > > Option 1: > > > > Extend your comparator to sort first o

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread Cedric Greevey
On Sat, Mar 24, 2012 at 9:39 PM, Cedric Greevey wrote: > In increasing order of difficulty... > > Option 1: > > Extend your comparator to sort first on the key you're actually > interested in, then if that key isn't different on the others > more-or-less arbitrarily. Or use this: (defn po->to [p

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread Cedric Greevey
In increasing order of difficulty... Option 1: Extend your comparator to sort first on the key you're actually interested in, then if that key isn't different on the others more-or-less arbitrarily. Option 2: Keep the data unsorted in a hash-set. Sort when you need sorted data, e.g. for user pr

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread Philip Potter
There's java.util.LinkedHashSet: http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashSet.html Its iterator will preserve insertion order, but it will ignore duplicates when inserted. It has a number of disadvantages: * only available on clj-jvm * not a persistent data structure, with al

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread mnicky
Thanks for the explanations! So is there a way to build a set or map that has sorting property independent from the element lookup? On Friday, March 16, 2012 2:03:15 AM UTC+1, Alan Malloy wrote: > > And this is exactly as it should be. The sorted set has no way to > compare items other than by y

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Alan Malloy
And this is exactly as it should be. The sorted set has no way to compare items other than by your comparator. If it just arbitrarily decided to use = instead of checking that (zero? (compare x y)) it would not be using your comparator. Note also that the behavior of contains? is consistent with c

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Mark Engelberg
It's not a problem with Clojure, it's also how Java behaves. For sorted-sets to work properly, your comparator *must* satisfy the trichotomy property of orderings. Consider a comparison predicate less?. The trichotomy property states that for all x,y, exactly one of the following hold: (less? x

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Stuart Campbell
Actually, sorted-map-by does behave the same way, but in your example you tried to lookup a value instead of a key: user> (def m (sorted-map-by #(< (%1 0) (%2 0)) [1 :a] [2 :b])) #'user/m user> (get m [1 :foo]) [2 :b] It looks like PersistentTreeMap.entryAt

Re: (.contains (transient #{}) 17) ==> true!?!

2011-03-15 Thread Alan
On Mar 14, 2:10 pm, Ken Wesson wrote: > On Mon, Mar 14, 2011 at 4:41 PM, Alan wrote: > > Thanks Ken, I found this too when I saw Tassilo's problem on irc > > (didn't notice it was on ML as well). I was going submit a patch for > > this, but if you've already done so let me know and I won't. > > I

Re: (.contains (transient #{}) 17) ==> true!?!

2011-03-14 Thread Ken Wesson
On Mon, Mar 14, 2011 at 4:41 PM, Alan wrote: > Thanks Ken, I found this too when I saw Tassilo's problem on irc > (didn't notice it was on ML as well). I was going submit a patch for > this, but if you've already done so let me know and I won't. I don't have a CA so no, I haven't. Go ahead. --

Re: (.contains (transient #{}) 17) ==> true!?!

2011-03-14 Thread Alan
Thanks Ken, I found this too when I saw Tassilo's problem on irc (didn't notice it was on ML as well). I was going submit a patch for this, but if you've already done so let me know and I won't. On Mar 14, 12:37 pm, Ken Wesson wrote: > On Mon, Mar 14, 2011 at 4:13 PM, Tassilo Horn wrote: > > Hi

Re: (.contains (transient #{}) 17) ==> true!?!

2011-03-14 Thread Ken Wesson
On Mon, Mar 14, 2011 at 4:13 PM, Tassilo Horn wrote: > Hi all, > > I've implemented IEditableCollection support for ninjudd's > PersistentOrderedSet.  But when using that, my application delivered > wrong results.  See <87hbb6c4qf@member.fsf.org> and follow-ups. > > I was able to track it down

Re: contains

2009-01-23 Thread wubbie
(some (set "aeiou") "e") is equiv to (some #{\a \e \i \o \u} "e") -> \e Finally, I can answer, instead of keep asking... -sun On Jan 23, 4:04 pm, Mark Volkmann wrote: > On Fri, Jan 23, 2009 at 2:51 PM, Chouser wrote: > > > On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann > > wrote: > > >> (c

Re: contains

2009-01-23 Thread Mark Volkmann
On Fri, Jan 23, 2009 at 3:43 PM, Chouser wrote: > > On Fri, Jan 23, 2009 at 4:13 PM, Mark Volkmann > wrote: >> >> I'm trying to implement pig latin using only what's in core in the >> simplest way possible. >> Does anyone see a simpler way? >> I'm not happy with using three functions (some, set

Re: contains

2009-01-23 Thread Chouser
On Fri, Jan 23, 2009 at 4:13 PM, Mark Volkmann wrote: > > I'm trying to implement pig latin using only what's in core in the > simplest way possible. > Does anyone see a simpler way? > I'm not happy with using three functions (some, set and str) to > determine if a letter is a vowel. I'm not qui

Re: contains

2009-01-23 Thread Chouser
On Fri, Jan 23, 2009 at 4:04 PM, Mark Volkmann wrote: > > Why does this work > > (some (set "aeiou") "e") > > but this doesn't > > (some #{"aeiou"} "e") > > I thought (set ...) was equivalent to #{...}. (hash-set ...) is equivalent to #{...} 'set' takes a single collection as an argument, which

Re: contains

2009-01-23 Thread Mark Volkmann
I'm trying to implement pig latin using only what's in core in the simplest way possible. Does anyone see a simpler way? I'm not happy with using three functions (some, set and str) to determine if a letter is a vowel. (defn pig-latin [word] (let [first-letter (first word)] (if (some (set "

Re: contains

2009-01-23 Thread wwmorgan
#{"aeiou"} is the set containing the String "aeiou". You want #{\a \e \i \o \u} On Jan 23, 4:04 pm, Mark Volkmann wrote: > On Fri, Jan 23, 2009 at 2:51 PM, Chouser wrote: > > > On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann > > wrote: > > >> (contains? "aeiou" letter) > > >> but that doesn't w

Re: contains

2009-01-23 Thread Stuart Halloway
Hi Mark, set takes a single argument, a coll, and #{} is a literal form that can have a variable number of args. To make them equivalent: (set "aeiou") -> #{\a \e \i \o \u} #{(seq "aeiou")} -> #{(\a \e \i \o \u)} Stuart > > On Fri, Jan 23, 2009 at 2:51 PM, Chouser wrote: >> >> On Fri, J

Re: contains

2009-01-23 Thread Mark Volkmann
On Fri, Jan 23, 2009 at 2:51 PM, Chouser wrote: > > On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann > wrote: >> >> (contains? "aeiou" letter) >> >> but that doesn't work either. > > user=> (some (set "aeiou") "dn'tndthsstinkngvwls") > \i Why does this work (some (set "aeiou") "e") but this doe

Re: contains

2009-01-23 Thread Mark Volkmann
On Fri, Jan 23, 2009 at 2:45 PM, Chouser wrote: > > On Fri, Jan 23, 2009 at 3:39 PM, Justin Johnson > wrote: >> On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann >> wrote: >>> >>> This must be something I learned months ago and then forgot ... >>> embarassing! >>> What's the easiest way to determi

Re: contains

2009-01-23 Thread Chouser
On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann wrote: > > (contains? "aeiou" letter) > > but that doesn't work either. user=> (some (set "aeiou") "dn'tndthsstinkngvwls") \i Or, if you must, user=> (clojure.contrib.seq-utils/includes? "aeiou" \o) true --Chouser --~--~-~--~~---

Re: contains

2009-01-23 Thread Mark Volkmann
On Fri, Jan 23, 2009 at 2:39 PM, Justin Johnson wrote: > On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann > wrote: >> >> This must be something I learned months ago and then forgot ... >> embarassing! >> What's the easiest way to determine if a sequence contains a given value? >> I thought there w

Re: contains

2009-01-23 Thread Chouser
On Fri, Jan 23, 2009 at 3:39 PM, Justin Johnson wrote: > On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann > wrote: >> >> This must be something I learned months ago and then forgot ... >> embarassing! >> What's the easiest way to determine if a sequence contains a given value? >> I thought there w

Re: contains

2009-01-23 Thread Justin Johnson
On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann wrote: > > This must be something I learned months ago and then forgot ... > embarassing! > What's the easiest way to determine if a sequence contains a given value? > I thought there would be something like this: (include? [2 4 7] 4) -> true > That d