I don't think I like the notion of a lazy-seq and an iterator, since reading
the iterator also changes it. Consider the case where you create a lazy-seq
from an iterator, and the iterator somehow escapes. Somewhere else the
iterator is read from, and now the data that where supposed to be in the
lazy-seq no longer exists.

I guess you could clone the iterator, but that would sort of remove the
purpose of using a lazy-seq in the first place.

Jonathan

On Sat, Jul 9, 2011 at 3:17 PM, David Powell <djpow...@djpowell.net> wrote:

>
> On Sat, Jul 9, 2011 at 10:10 AM, stu <stuart.hungerf...@gmail.com> wrote:
>
>> Hi,
>>
>> I'd like to make use of Java classes implementing the Java2D
>> PathIterator interface:
>>
>>
>> http://download.oracle.com/javase/6/docs/api/java/awt/geom/PathIterator.html
>>
>> Which leads to a serious impedance mismatch between immutable Clojure
>> data structures and the iterator's approach of calling next() until
>> isDone() and using currentSegment() to retrieve the point
>> coordinates.
>>
>> I'd guess this kind of iterator is widely used in the Java world, so
>> can some kind person point to an example of Clojure code using a Java
>> iterator in this way?
>>
>> Thanks in advance,
>>
>> Stu
>>
>
> Clojure has a built in function, iterator-seq, which converts a
> java.util.Iterator to a lazy-seq.  Lazy-seq's keep a copy of each data item
> that they have grabbed from the iterator, so they hide the mutability of
> Iterators.
>
> http://clojuredocs.org/clojure_core/clojure.core/iterator-seq
>
> Your interface doesn't subclass java.util.Iterator though, so you would
> need to make something similar.
>
> I haven't tested this, but maybe something like this:
>
>
> (defn pathiterator-seq
>   [i]
>   (when-not (.isDone i)
>     (lazy-seq
>      (.next i)
>      (let [arr (make-array Double/TYPE 6)
>            type (.currentSegment i arr)]
>        (cons {:type type :coords (into [] arr)}
>              (pathiterator-seq i))))))
>
>
> --
> Dave
>
>
>  --
> 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
>

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