On Jan 14, 1:03 pm, Jason Wolfe <jawo...@berkeley.edu> wrote:
> > > (import '(java.util HashSet))
> > > (defn distinct-elts? "Are all of the elements of this sequence
> > > distinct?  Works on infinite sequences with repititions, making it
> > > useful for, e.g., detecting cycles in graphs."
> > >  [s]
> > >  (let [hs (HashSet.)]
> > >    (loop [s (seq s)]
> > >      (cond (empty? s)                    true
> > >            (.contains hs (first s))        false
> > >            :else (do (.add hs (first s)) (recur (rest s)))))))
>
> > Is there any reason the builtin 'distinct?' couldn't handle these
> > cases as well?  What does "elts" stand for?
>
> I suppose this is the same as (apply distinct? s).  

Except that distinct? can't take 0 arguments, so (apply distinct? nil)
fails rather than returning true.  Does adding a 0-arg case to
distinct? sound reasonable?

-Jason
--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to