Welcome! Please see the About page for a little more info on how this works.

0 votes
in Docs by

Applying meta to a lazy-seq causes realization:

(def x (vary-meta (lazy-seq (prn :realized)) assoc :foo :bar)) :realized

This might be surprising, so modify docstring of lazy-seq to mention it.

Patch:

7 Answers

0 votes
by

Comment made by: alexmiller

I think it's likely that seq() is called here so that the old LazySeq instance and the new one share the sequence. Otherwise the pre-meta and post-meta versions would be performing the same function calls on the same inputs but would be disconnected, which seems bad.

0 votes
by

Comment made by: alexmiller

I'm not really sure where this would be documented. Maybe on the http://clojure.org/metadata page?

0 votes
by

Comment made by: mpenet

That would make sense yes and on the docstring of lazy-seq as well.

0 votes
by

Comment made by: alexmiller

I added a sentence to the metadata page and updated the description to be more applicable here to a docstring change.

0 votes
by

Comment made by: michaelblume

With this patch, with-meta doesn't realize the seq, but realization still only happens once -- would this be an acceptable approach?

0 votes
by

Comment made by: michaelblume

Added test

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1800 (reported by mpenet)
...