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