On Fri, Jan 23, 2009 at 2:45 PM, Chouser <chou...@gmail.com> wrote: > > On Fri, Jan 23, 2009 at 3:39 PM, Justin Johnson > <ajustinjohn...@gmail.com> wrote: >> On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann <r.mark.volkm...@gmail.com> >> 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 doesn't exist. > > Sure it does: > > user=> (require 'clojure.contrib.seq-utils) > nil > user=> (clojure.contrib.seq-utils/includes? [2 4 7] 4) > true > > :-)
Thanks! It's too bad something this basic isn't in the core. >>> I know I can do this: (some #{4} [2 4 7]) >>> Having to create a set seems overkill. > > It's not! It's beautiful and succinct. And it let's you test for any > of several values, and then tells you which it found: > > user=> (some #{3 4 5} [2 4 7]) > 4 Well ... I agree that it's beautiful and succinct IF you want to test multiple values. I just think there should be a simpler way to test for one value that is in the core. >> user=> (contains? [1 2 3] 1) >> true > > This is doing something different: > > user=> (contains? [2 4 7] 7) > false > > That's telling you that the vector has no value at index 7. Yeah, I just figured that out while you were composing your reply. Thanks! -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---