out of curiosity, if 2 siblings have the same value for their :value
attribute, you just keep the first one you encounter, and throw away the
others with the same :value attribute ? Is it because they also have the
same attributes altogether, or because you're relying on an "importance"
criteria based on the position of the siblings within the vector ?
additional question: can you show us the whole content of a node map/record
?

2010/11/8 Greg <g...@kinostudios.com>

> So... I tried, and failed, to use transients properly.
>
> The function below, new-gen, takes a sequence of "nodes" and creates a new
> generation of nodes out of them using the functions "transform-left" and
> "transform-right".
>
> Each node in the sequence has two children, one is created with
> transform-left, the other with tranform-right.
>
> The desired result is a new sequence containing all the children,
> representing the "new generation".
>
> The catch is that some of the children are aborted at birth according the
> following rules:
>
> 1) If the child has an existing parent with a value equal to its own, it is
> left out of the sequence
> 2) If the child has an existing sibling with a value equal to its own, it
> too is left out of the resultant sequence
>
> The function is listed below:
>
> (defn new-gen [a]
>  (let [t (transient [])]
> (doseq [f a]
> (doseq [n [(transform-left f) (transform-right f)]]
>  (when-not (contains? #(= (:val n) %) (map :val (parents n)))
> (conj! t n)))) ;; <-- transient bashing!!
>  (distinct #(= (:val %1) (:val %2)) (persistent! t))))
>
> I'm also using modified versions of 'distinct' and 'contains?', the full
> source for them (and the new-gen function) is available in
> syntax-hightlighted goodness here:
>
> http://paste.pocoo.org/show/288063/
>
>
> The question is: how do I write new-gen in an elegant way and avoid
> "bashing the transient"?
>
> I must say it would be really nice if this was considered kosher.. as it
> does work just fine. It would also be useful to know why transient bashing
> is frowned upon.
>
> Any help is greatly appreciated!
>
> - Greg
>
> --
> 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<clojure%2bunsubscr...@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 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