Newb question about quotation marks

Discussion of Common Lisp
Post Reply
Jonsul
Posts: 18
Joined: Mon Apr 19, 2010 7:56 am

Newb question about quotation marks

Post by Jonsul » Tue May 04, 2010 11:46 am

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

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Newb question about quotation marks

Post by gugamilare » Tue May 04, 2010 11:59 am

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

Jonsul
Posts: 18
Joined: Mon Apr 19, 2010 7:56 am

Re: Newb question about quotation marks

Post by Jonsul » Tue May 04, 2010 12:11 pm

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.

Jonsul
Posts: 18
Joined: Mon Apr 19, 2010 7:56 am

Re: Newb question about quotation marks

Post by Jonsul » Tue May 04, 2010 1:14 pm

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.

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Newb question about quotation marks

Post by ramarren » Tue May 04, 2010 2:41 pm

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.

Post Reply