0

With a elisp piece of code:

(message "%s" (read-from-string "(setq a \"a string here\" )"))

I got result:

((setq a a string here) . 25)

But I want result is:

((setq a "a string here") . xxx )

I can't find in document info to do this

2
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Jan 24, 2023 at 14:47
  • Nothing in your question shows an attempt to create a dotted list with 25 or xxx as cdr. And none of the code you said you tried does that. Please clarify the questions.
    – Drew
    Jan 24, 2023 at 14:50

1 Answer 1

0
%s means print a string argument.  Actually, prints any object, with ‘princ’.
%S means print any object as an s-expression (using ‘prin1’).

Hence:

(message "%S" (read-from-string "(setq a \"a string here\" )"))
=> "((setq a \"a string here\") . 25)"

I.e. The read-from-string return value was fine already; it was just the way you were printing it; princ vs prin1.

1
  • Thanks for pointing out! The command works fine.
    – ri wen
    Jan 24, 2023 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.