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 [limit 1000]
    (< (bounded-count limit xs) limit)))

(looks-finite? (map inc (range))) ;; => false
(looks-finite? (map inc (range 100))) ;; => true

I hope that helps.

Juan
El domingo, 1 de noviembre de 2020 a las 20:06:39 UTC-3, Austin Haas 
escribió:

>
> 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 don't want to constrain every 
> collection.
>
> And I know that lazy seqs aren't always realized, but that doesn't seem to 
> help if they are infinite:
>
> user=> (str (map inc (range 10)))
> "clojure.lang.LazySeq@c5d38b66"
>
> user=> (str (map inc (range)))
> <never ends>
>
> Thanks.
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/5318a41e-7353-4c81-b1d4-99a3c54e3120n%40googlegroups.com.

Reply via email to