Okay, I just found a negative answer to this on SO:
http://stackoverflow.com/questions/1056061/adding-metadata-to-a-lazy-sequence

However, to give a bit more context for my concrete use case: I'm
building a Turtle (RDF) parser which emits a lazy seq of triples,
basically a seq of 3-element vectors where the first 2 are URIs. In
Turtle these URIs can be abbreviated using namespace prefixes declared
at the beginning of the file, e.g given this TTL chunk:

@prefix ex: <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix doap: <http://usefulinc.com/ns/doap#> .

ex:clojure rdf:type doap:Project ;
    doap:name "Clojure" .

results in this seq of 2 triples:

(["http://example.org/ns#clojure";
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
"http://usefulinc.com/ns/doap#Project";]
 ["http://example.org/ns#clojure"; "http://usefulinc.com/ns/doap#name";
"Clojure"])

Sinc the prefix map is built iteratively as part of the parsing I was
hoping to attach it as meta data to the returned lazy-seq, since I
can't see any other way of returning this map apart from attaching to
every single triple in the seq (which seems like overkill).

Are there any other options I'm missing here?

On 12 July 2013 14:42, Karsten Schmidt <i...@toxi.co.uk> wrote:
> Hello, what is the correct way (assuming there is one) to create a lazy-seq
> with metadata attached? The below works for short seqs, but causes a stack
> overflow for large ones, which obviously means the lazy-seq mechanism is
> altered/broken if wrapped with `with-meta`. So I guess there must be another
> way...
>
> (defn meta-test
>   [i]
>   (with-meta
>     (lazy-seq
>       (when (pos? i) (cons i (meta-test (dec i)))))
>     {:range i}))
>
> (meta (meta-test 100))
> ; => {:range 100}
>
> Thanks for any insights!
> K.



-- 
Karsten Schmidt
http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to