Closing the loop: An insteractive blog post made out Alex's detailed
explanations:
http://blog.klipse.tech/clojure/2016/11/24/stringify-clojure.html

On Mon, 21 Nov 2016 at 00:29 Alex Miller <a...@puredanger.com> wrote:

> Stepping back... Clojure's print system has two families of functions -
> one for human consumption and one for data. Many kinds of Clojure data
> print the same in either mode (strings are one exception).
>
> The human printing is most commonly encountered with functions like
> println, print. and str. It's designed to print things to the repl or to
> the console for a person to read. Strings print without the surrounding
> quotes and newlines are really printed as newlines, etc. str doesn't
> directly use either Clojure printing mode but instead prints the toString()
> of each object (this is Java's built-in printing system). For strings, both
> Clojure's printing and str wind up just relying on Java to print a String
> in a "human-readable" way. Clojure types (like maps) implement toString()
> to route back into the Clojure printing system. In general, the REPL will
> use data mode when printing the result of a function (this behavior can be
> modified).
>
> The data print functions are things like pr (like print, but for data),
> prn (like println, but for data), and pr-str (like str, but for data). The
> idea with the data printers is that the thing you print should be readable
> by Clojure. So pr-str etc will print a string as the actual characters
> Clojure would need to read that string back as data.
>
> This is the big picture. I have left the even more complicated pretty
> printing (pprint) and cl-format (following CommonLisp) parts. You are in a
> maze of twisty little passages, all alike. If you look too hard at it, you
> are likely to be eaten by a grue. The print and pprint systems also have
> many dynamic vars to influence behavior and a number of multimethods
> intended for extension or modification. In particular, you can provide your
> own printers for either built-in types or custom records or types by
> extending things like print-method (human) or print-dup (data).
>
> If anyone wanted to write a mini Clojure book, this would be a killer
> topic.
>
> Alex
>
> On Sunday, November 20, 2016 at 12:30:58 PM UTC-6, Yehonathan Sharvit
> wrote:
>
> Alex, what is the exact difference between pr-str and str (when passing a
> single arg)?
>
> On Sun, 20 Nov 2016 at 19:40 Alex Miller <a...@puredanger.com> wrote:
>
> pr-str is the companion to read-string
>
> Although, there are many many cases where this round trip will not result
> in the same input. Things like reader macros, autoresolved keywords, etc
> will be expanded in the reader.
>
> --
> 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 a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/_qzaqqkMHHw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/_qzaqqkMHHw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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