3

I would like to convert these two strings

"(a b c)"

"(9 . 3)"

to these

(a b c)

(9 . 3)

I'd had some luck with the first one evaluating this,

(mapcar 'intern (split-string (string-trim "(a b c)" "(" ")"))) basically, removes parentheses from string, splits it to ("a" "b" "c"), then calls intern to turn all the elements to symbols and yields (a b c). When evaluating this with "(9 . 3)" though, It escaped all elements and yields (\9 \. \3), this however, is not the same as (9 . 3) that I wanted.

2
  • 1
    Please see my answer below. Note that your question is related to the fact that: In lisp, code (the string), code (in memory), data (list, etc.), read & print representations, how lisp parse its code are all closely related.
    – TerryTsao
    May 18 at 9:51
  • Yes, I saw your answer and it solved my problem wonderfully, you answered so quick that I had to wait 10 minutes to accept the answer.
    – C11g
    May 18 at 9:54
5
ELISP> (read "(a b c)")
(a b c)

ELISP> (read "(9 . 3)")
(9 . 3)

If by (9 . 3) you mean you'd like a cons, then my answer would work. Note however if you actually would like a dot, my answer not so much.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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