Inversion of eval-string function

Started by Fritz, March 23, 2010, 06:57:12 AM

Previous topic - Next topic

Fritz

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


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


(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

#1
How about:

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

Fritz

#2
Quote from: "HPW"How about... source


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


> (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)nn"
> (source (sym (test 0 1)))

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