Page 1 of 1

Newb question about quotation marks

Posted: Tue May 04, 2010 11:46 am
by Jonsul
I have just a little question to ask. To teach myself cl I've been making a webpage library for cgi, thought it would be a good start since I'm already a web developer. I got a lot of it working pretty well so far but came up with an issue while trying to do attributes. I don't know how to escape quotation marks (") in format. I've been reading a lot about format but still haven't seen anything for that. Is there any easy way to do it like the normal \" I already know. Or maybe ~" or something?

thank you

Re: Newb question about quotation marks

Posted: Tue May 04, 2010 11:59 am
by gugamilare
Jonsul wrote:I have just a little question to ask. To teach myself cl I've been making a webpage library for cgi, thought it would be a good start since I'm already a web developer. I got a lot of it working pretty well so far but came up with an issue while trying to do attributes. I don't know how to escape quotation marks (") in format. I've been reading a lot about format but still haven't seen anything for that. Is there any easy way to do it like the normal \" I already know. Or maybe ~" or something?

thank you
Didn't you try \"?

Code: Select all

cl-user> (format t "\"Hello World!\"~%")
"Hello World!"
nil

Re: Newb question about quotation marks

Posted: Tue May 04, 2010 12:11 pm
by Jonsul
Sorry I should of mentioned I'm trying to output with (format nil "\"hello world\"") or even write-line so it creates a document. But it outputs as: "\"hello world\""
When making an attribute, having it output as "<img src=\"/home/user/me.gif\" />" isn't good.

Re: Newb question about quotation marks

Posted: Tue May 04, 2010 1:14 pm
by Jonsul
Nevermind it was a bit of confusion on my part. When I put in (write-line "\"hello world\"") in slime it outputs it without taking out the escape characters. as:

Code: Select all

"\"hello world\""
But in practice after trying to actually make a cgi apt to generate a page with the escape characters it works ^-^
It was kinda confusing though, why does slime output the escape characters when using (format nil "\"") but not actually output them? :/

Took me a long time to realize this after several times of unsuccessfully using " or " or whatever.

Re: Newb question about quotation marks

Posted: Tue May 04, 2010 2:41 pm
by ramarren
Jonsul wrote:It was kinda confusing though, why does slime output the escape characters when using (format nil "\"") but not actually output them? :/
There are two modes of output in CL as applied to escaping. One, which is used by the REPL, is to output in such a format that the object can be read back in by the Lisp reader, so a string is surrounded in quotes and any quotes in a string are escaped. The other is raw output, which is what you want. The mode and other options are controlled by which function is used and dynamic variables, described in Hyperspec.

You should have seen the form printed twice when using WRITE-LINE, one from the printing form, and the other from the REPL. If you did not, then likely the standard output is going into the *inferior-lisp* buffer. You might want to configure the SWANK:*GLOBALLY-REDIRECT-IO* option. Also, (format nil ...) doesn't print anything, it creates a new string object.