Thanks Meikel!

This is a really neat way of writing it, I'm going to need to study this one as 
it uses some functions I'm not super familiar with (so thanks very much for 
introducing me to them and coming up with this elegant example!).

The only thing is that while your distinct-by function doesn't seem to work... 
The nodes are record objects (created via the 'defrecord') and I'm guessing it 
has to do with how clojure's "contains?" functions works.

- Greg

On Nov 8, 2010, at 3:24 PM, Meikel Brandmeyer wrote:

> Yeah, golfing at late night..
> 
> (defn distinct-by
>    [keyfn coll]
>    (let [step (fn step [xs seen]
>                 (lazy-seq
>                   ((fn [[f :as xs] seen]
>                      (when-let [s (seq xs)]
>                        (if (contains? seen (keyfn f))
>                          (recur (rest s) seen)
>                          (cons f (step (rest s) (conj seen f))))))
>                      xs seen)))]
>      (step coll #{})))
> 
> (defn new-gen
>  [a]
>  (->> a
>    (mapcat (juxt transform-left transform-right))
>    (remove (fn [n] (some #(= (:val n) (:val %)) (parents n))))
>    (distinct-by :val)))
> 
> I modified your distinct to not capture a core name. Also it now exploits 
> that seen is a set. Also your contains? is called some.
> 
> Hope this helps.
> 
> Sincerely
> Meikel
> 
> -- 
> 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

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