Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping double quote in Common Lisp

How to escape double quotes while concatenating a string? For example i hoped

(concatenate 'string "Mama said: " "\"Son, your life is an open book...\"")

to give:

"Mama said: "Son, your life is an open book...""

but instead returned it with backslashes as:

"Mama said: \"Son, your life is an open book...\""
like image 911
oakenshield1 Avatar asked Mar 14 '12 16:03

oakenshield1


People also ask

How do you escape a double quote?

“Double quotes 'escape' double quotes“ When using double quotes "" to create a string literal, the double quote character needs to be escaped using a backslash: \" .

How do you escape quotation marks in a string?

' You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.

When to use double quotes?

Use double quotation marks (“”) around a direct quote. A direct quote is a word- for-word report of what someone else said or wrote. You use the exact words and punctuation of the original. Harriet Jacobs writes, “She sat down, quivering in every limb” (61).


1 Answers

The returned value is printed readably, that is, using a representation that can be parsed with READ into a CL object. If you use a function like PRINC which prints a string as-is you will see that the quoting did what you wanted (the outer quotes are not part of the string):

CL-USER> (princ (concatenate 'string "Mama said: " "\"Son, your life is an open book...\""))
Mama said: "Son, your life is an open book..."
"Mama said: \"Son, your life is an open book...\""

The first line is the result of PRINC, the second one of the PRINT part of the READ-EVAL-PRINT-LOOP.

like image 58
Ramarren Avatar answered Oct 23 '22 19:10

Ramarren