Hi guys,
This is my first post to the group, but have been following the
discussions for almost a year. Many thanks to Rich Hickey for creating
a fantastic future-proof language which is a pleasure to use and to
the great community!
The following function (as part of a chemistry-related application)
filters the elements of a sequence that a repeated a specified number
of times. Wondering if the function could be simplified and written
without the reference (newseq).
Thanks a lot!
Nik

(defn filter-repeats [seq n]
  "Returns a vector of the elements of a sequence that are repeated n
times"
  (let [newseq (ref [])]
    (doseq [u (set seq)]
      (when (= (count (filter #(= % u) seq)) n)
        (dosync (commute newseq conj u))))
    @newseq))

Usage e.g.
(filter-repeats '(2 3 1 4 2 2 4 3 5 ) 2)
[3 4]


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