So here is a new attempt at the quantize function so that I no longer have 
to deal with the "infinity" problem:

(defn quantize-2 
  [x params]
  (let [f (partial (fn [a [b c]] (cond(<= a c) b)) x)]
    (println (first (filter #(not (nil? %))(map f (into [](partition 2 
params))))))
    (or 
     (first (filter #(not (nil? %)) (map f (into [](partition 2 params))))) 
     (last params))))


params now has this form: 

[:zone-1 120 :zone-2 150 :zone-3 165 :zone-4 180 :zone-5]


i.e. the values to return are intermingled with the "boundaries". I 
normally don't like mixing things but you've gotta admit that it looks just 
like how you would draw heart rates on a schema on paper: zone1 | zone 2 | 
zone 3 | zone 4 | zone 5 and you would probably have the values 120, 150, 
165 and 180 written in between the zone names, just above the | characters.

The way I got rid of the infinity is by using the "or". I'm looking for the 
first non null value (when trying to find whether x is <= 120, <= 150, 
<=165, <=180, and if I don't find any, then it must be that we're in the 
last "category" of my params collection.

Still not sure whether it's the optimum way to do it but I'll continue 
researching (after all, this is not a professional project, I have no 
deadline, and I can keep trying to improve  - great way to learn).
The feedback I got on this post got me working and scratching my head all 
weekend. This is great. 

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to