'filter' is for getting a subset of the elements in a collection.  For
getting the names of the provinces, what you want is to get all the
keys from your 'provs' map, which can be done via the 'keys' function.

user=> (keys provs)
("p1" "p2" "p3" "p4")

Personally, I find ClojureDocs' Quick Reference tremendously helpful
whenever I'm looking for a function to do something:

http://clojuredocs.org/quickref/Clojure%20Core

Hope this helps!

On Dec 21, 11:06 am, Anclj <anb...@gmail.com> wrote:
> Hi again,
>
> I still don't know how to use the filter function.
>
> I have a map of "provinces - seats" like: (def provs {"p1" "5", "p2"
> "8", "p3" "13", "p4" "11"})
> And a sequence of "province - party - votes" like: (def votes [["A"
> "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"] ["B" "p2" "21"]])
>
> In order to get the lazy sequence for every province, I have made a
> function like: (defn getseq [prov party] (...))
>
> But I don't know how to get each province ("p1", "p2", "p3", ...).
>
> Doing: (take 1 provs)
> I get: (["p1" "5"])
>
> Any idea of how could I get "p1"? So I can make a recursive call to my
> getseq function with "p1", "p2", ...
>
> Thanks again.
>
> On Dec 21, 2:21 am, Ken Wesson <kwess...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Mon, Dec 20, 2010 at 5:05 PM, Anclj <anb...@gmail.com> wrote:
> > > Thanks a lot for the fast reply!
> > > Now I have the vector as I wanted.
>
> > > I have been playing with your code: (map #(/ votes %) (iterate inc 1))
>
> > > user=> (take 10 (map #(/ 100 %) (iterate inc 1)))
> > > (100 50 100/3 25 20 50/3 100/7 25/2 100/9 10)
>
> > > I have managed to put that in a lazy sequence:
> > > user=> (def ls (lazy-seq (map #(/ 100 %) (iterate inc 1))))
> > > #'user/ls
>
> > Eh. (map #(/ votes %) (iterate inc 1)) itself produces a lazy
> > sequence, since map and iterate are lazy.
>
> > > I don't know how to filter and work with the vector & map in order to
> > > apply that function for each party, in each province.
> > > I have been trying to use the filter function but I get the following
> > > error:
>
> > > user=> (filter #"A" [["A" "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"]
> > > ["B" "p2" "21"]])
> > > java.lang.ClassCastException: java.util.regex.Pattern cannot be cast
> > > to clojure.lang.IFn
>
> > For this, you can just use #(= "A" %) as your predicate; there's no
> > need to use regex matching.
>
> > If you need a regex, use #(re-matches #"pattern" %) as your predicate,
> > instead of the regex itself.
>
> > > Thanks again and I will be posting any advances!
>
> > You're welcome.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to