[plt-scheme] problem with \"

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Dec 13 12:05:45 EST 2005

At Tue, 13 Dec 2005 15:10:33 +0000, "Alexandre Hubert" wrote:
> Here is my problem : I have a list, for instance (x y \"z\") , in which the 
> double-quotes are preceded by a backslash, and I want to format it to obtain 
> the list (x y "z") (e.g. without the backslashes). The only way I found to 
> do it is to write the list into an external file with fprintf "~a", then 
> read the file to get the list without the backslashes, and I would like to 
> do it without having to write in an external file. I tried format "~a", I 
> tried display and fprintf "~a" into a open-output-string, and none of these 
> worked, the backslashes remain (and I am surprised by the behavior of 
> fprintf "~a", as if the port is open on an external file, the backslashes 
> are removed, while if it is open on a string, they are not. Shouldn't 
> fprintf write the same thing whatever the port is open on ?)

Yes, `fprintf' behaves the same for all ports. I think there must be
some confusion at a different point.

If you evaluate
  (format "~s" '(x y "z"))

then the result prints as

  "(x y \"z\")"

but the backslashes are not really characters in this string. They are
just escaping the quotes for the enclosing string. You can see that by

  (display (format "~s" '(x y "z")))

which prints

 (x y "z")

to the current output port and returns void.

Your actual example probably doesn't match the above, but I can't quite
tell what you need. If you can show example code, then we can probably
help more.


Posted on the users mailing list.