(pr-str '(+ 1 2)) :

pr-str is not given code-as-data , because it's not a macro. pr-str is given
the result of first evaluating its arg, that is '(+ 1 2). And evaluating '(+
1 2) results in the list (+ 1 2).
So pr-str is right, your assumptions were wrong.

To achieve your goal, just use (pr-str ''(+ 1 2)).

HTH,

-- 
Laurent

2010/9/29 K. <kotot...@gmail.com>

> Hello,
>
> I have some questions about how to use the prn functions.
>
> From the documentation of the prn function:
> "[...] By default, pr and prn print in a way that objects can be read
> by the reader [...]"
>
> In this case, why does the prn-str function does not quote sequences?
>
> For instance (pr-str '(+ 1 2)) returns "(+ 1 2)", which can not be
> read back since (eval (read-string (pr-str '(+ 1 2)))) returns 3!
>
> There is the *print-dup* function but it does not produce a string
> readable by an (advanced) user:
>
> (binding [*print-dup* true]
>        (pr-str '(+ 1 2)))
>
> returns "^#=(clojure.lang.PersistentArrayMap/create {:line 1}) (+ 1
> 2)"
>
> where I just would like to display to the user "'(+ 1 2)"
>
>
> So how can one print and read back quoted s-expressions so that a user
> can modify them?
>
> I have implemented a pr-str-data function:
> (defn- pr-str-data [data]
>  (if (seq? data)
>    (str "'" (pr-str data))
>    (pr-str data)))
>
> but there should be a better way.
>
> Thanks in advance for your help.
>
> --
> 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<clojure%2bunsubscr...@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 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

Reply via email to