Here is the code I'm working on.  The first function is wanted. The second
is not. (and the duplication is waiting to be factored out somehow...)

Is there an idiomatic Clojure way to use map-of-distances on the "Line of
Note" below, instead of map-of-distances* ?

Thanks for all your help.

(defn map-of-distances [origin & locations]
  (loop [dists {} locs locations]
    (if (seq locs)
      (let [[loc & more] locs
            dist (dist-in-miles origin loc)
            dists (assoc dists loc dist)]
        (recur dists more))
      dists)))

(defn map-of-distances* [origin locations]
  (loop [dists {} locs locations]
    (if (seq locs)
      (let [[loc & more] locs
            dist (dist-in-miles origin loc)
            dists (assoc dists loc dist)]
        (recur dists more))
      dists)))

(defn relative-distance
  "Gives distance * frequency.
  frequencies are in days out of 365"
  [origin & locations-n-frequencies]
  (let [loc-w-dists (map-of-distances* origin (take-nth 2
locations-n-frequencies))  ;;;;;  <-- Line of Note
        loc-w-freqs (apply hash-map locations-n-frequencies)]
    (multi-fmap (fn [d f] (* d f)) loc-w-dists loc-w-freqs)))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to