Inversion of eval-string function

Q&A's, tips, howto's
Locked
Fritz
Posts: 66
Joined: Sun Sep 27, 2009 12:08 am
Location: Russia

Inversion of eval-string function

Post by Fritz »

I have a variable, which contains some text with special symbols:

Code: Select all

> {some symbols \/""}
"some symbols \\/\"\""
I want to save contents of this variable to the text file, with all that backslashes before quotes et cetera. Now I use function

Code: Select all

(define (gnirts-lave x)
  (1 -1 (string (list x))))
But, may be, there exists more direct way to get "texted" value of a variable?

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: Inversion of eval-string function

Post by HPW »

How about:

Code: Select all

> (setq a "some symbols \/\"")
"some symbols /\""
> (source 'a)
"(set 'a \"some symbols /\\\"\")\r\n\r\n"
Hans-Peter

Fritz
Posts: 66
Joined: Sun Sep 27, 2009 12:08 am
Location: Russia

Re: Inversion of eval-string function

Post by Fritz »

HPW wrote:How about... source
Thanx, "source" looks promising for me. Only problem: source + sym dislike lists for some reason:

Code: Select all

> (set 'test '(("a" '(1 2 3 4 5)) ("b" 52) ("c" "something")))
(("a" '(1 2 3 4 5)) ("b" 52) ("c" "something"))
> (source (sym (test 1 1)))
"(set  (sym \"52\" MAIN:MAIN)  nil)\n\n"
> (source (sym (test 0 1)))

ERR: number or string expected in function sym : (test 0 1)

Locked