Page 1 of 1

printing a backslash

Posted: Mon Nov 29, 2010 8:07 am
by lrodrig
Hello,

How can I print a single backslash in SBCL? I mean, the expression:

(format nil "\\")

returns "\\" and not "\". If I type a single backslash, as can be expected, it is interpreted as an escape character for the following element in the string.

Does someone know how to solve this problem in SBCL?

Thanks in advance.
Luis.

Re: printing a backslash

Posted: Mon Nov 29, 2010 8:28 am
by lrodrig
Hello again:

I just have solved my problem. Although 2 characters are printed, the string created contains a single backslash.

Regards,
Luis.

Re: printing a backslash

Posted: Mon Nov 29, 2010 8:31 am
by ramarren
Values in Common Lisp can be printed readably or not, where the readability applies to the CL reader, which reads symbolic expression according to CL syntax. Since backslash is an escape character it has to be escaped when printed readably. Return values in the REPL are usually printed readably.

Compare:

Code: Select all

CL-USER> (print "\\")

"\\" 
"\\"
CL-USER> (princ "\\")
\
"\\"
The first line is the output of printing operator, the second output of the P part of REPL.

Re: printing a backslash

Posted: Mon Nov 29, 2010 8:36 am
by lrodrig
Hello,

Thank you very much for the explanation. Now, it is perfectly clear.

Regards,
Luis.