(defrecord Pos [name value]
  Object
  (toString [this]
        (str "<Name: " name ", Value: " value ">")))

 (def actions [(Pos. "IBM", -50)
           (Pos. "ACCOR", -30);
           (Pos. "IBM", -10);
           (Pos. "APPLE", -20);
           (Pos. "AIRFRANCE", -20)])

(def options [(Pos. "IBM", 55)
          (Pos. "ACCOR", 40)
          (Pos. "AIRFRANCE", 10)
          (Pos. "LUFTHANSA", 100)])

(defn process [options actions]
  (cond (nil? (seq options)) actions
    (nil? (seq actions)) options
    :else (for [option options
            action actions
            :when (= (:name option)
                 (:name action))]
        [(Pos. (:name option)
               (min 0 (+ (:value option)
                 (:value action))))
         (Pos. (:name option)
               (max 0 (+ (:value option)
                 (:value action))))])))

(defn match [[options actions]]
  (reduce #(do [(conj (first %1)  (first %2))
        (conj (second %1) (second %2))])
      [[] []]
      (process options actions)))

(println "Options:" (map str options))
(println "Actions:" (map str actions))

(println "--after match--")

(let [[options actions] (match [options actions])]
  (println "Options:" (map str options))
  (println "Actions:" (map str actions)))

-- 
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