I wrote a little library for this purpose a while ago:
https://github.com/borkdude/finitize
--
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
I'm not 100% happy with this plus it doesn't really answer the original
question, but in case it helps in some way ...
Recently, I had a record I was working on that holds a seq that could be a
lazy infinite seq that I ended up using this as the major part of
print-method implementation:
(def
Thanks, Justin!
Yeah, I noticed that range doesn't return an instance of
clojure.lang.LazySeq, so I added a print-method for clojure.lang.Iterate.
And that one seems to work as expected, but apparently you can't override
the print-method for clojure.lang.LazySeq.
But this doesn't seem like a
hit send too soon --
also, that print-method doesn't catch all lazy values
user=> (instance? clojure.lang.LazySeq (range))
false
user=> (supers (class (range)))
#{java.lang.Iterable java.util.List clojure.lang.Obj
clojure.lang.IPending java.io.Serializable clojure.lang.IHashEq
> The next step might be to investigate why infinite lazy seqs don't print as
> clojure.lang.LazySeq, like the finite ones.
that printing of "clojure.lang.LazySeq@c5d38b66" relies on completely
realizing the input, as it relies on the hash, which relies on the
fully realized value
On Mon, Nov
Thanks, Juan.
I don't need to know the length of the seq, though, only that it is lazy. I
don't want to realize *any* lazy seqs. Ideally, I'd like to be able to
print any data structure and have all lazy seqs print just like it does in
the example I gave above (i.e.,
Hi Austin,
Since there is no way to know the length of a lazy-seq without realizing
it, I think your only choice is to set a limit on it by binding
*print-length* if you are not sure about the sequence.
Other thing you can try is bounded-count like this :
(defn looks-finite? [xs]
(let
How can I make sure that a logging function won't try to realize an
infinite lazy seq that could be anywhere in the arguments passed to the
logging function?
Is there some way to guarantee that lazy seqs won't be realized when
converting to a string?
I know I can bind *print-length*, but I