Hi,

I am writing to ask if a behavior that I find strange is a bug or intended? In the latter case I would like to learn why is it so.

In the REPL I see the following, that I think is OK:

user=> (def test-data (lazy-seq [(str ["ZiZi"])]))
#'user/test-data
user=> test-data
("[\"ZiZi\"]")

However, if I call "print" in between the previous 2 lines, test-data becomes different at the end:

user=> (def test-data (lazy-seq [(str ["ZiZi"])]))
#'user/test-data
user=> (print test-data)
([ZiZi])nil
user=> test-data
("[ZiZi]")

I found that the "binding" of  *print-readably* in the code of "print" makes the difference. If it is nil (as in print), I get the faulty value. If it is true, then I get the right (inner-quoted) value.

I learned (from e.g. Stuart Halloway at http://grokbase.com/t/gg/clojure/149d3t0gwh/schrodingers-cat-in-clojure) that mixing lazy evaluation and I/O can lead to confusing situations and that is normal. However here I feel that I get different values of the same expression depending on which action triggers its realization: if it is (e.g.) print, then it is realized in a faulty way: "[ZiZi]" is not correct, since ZiZi should be quoted inside the string by \"-s. (I know the missing inner quotes are not just a REPL printing issue as I distilled this question after spending hours to hunt down strange error messages in a real commercial program.) In other words it seems to me that having *print-readably* nil, makes the realization of this lazy-seq failing.

I also see that the problem disappears if I do not use lazy-seq (or map...) or if I code the string directly (without "str"):

user=> (def test-data (lazy-seq ["[\"ZiZi\"]"]))
#'user/test-data
user=> (print test-data)
(["ZiZi"])nil
user=> test-data
("[\"ZiZi\"]")

and

user=> (def test-data [(str ["ZiZi"])])
#'user/test-data
user=> (print test-data)
[["ZiZi"]]nil
user=> test-data
["[\"ZiZi\"]"]

I verified this behavior both in (pure, i.e. not Lein) REPL of Clojure 1.8 and 1.9.0-alpha20.

Please help me understanding what's going on here.

Thanks,P


--
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/d/optout.

Reply via email to