printing a backslash

Discussion of Common Lisp
Post Reply
lrodrig
Posts: 17
Joined: Thu Sep 16, 2010 4:52 pm

printing a backslash

Post by lrodrig » Mon Nov 29, 2010 8:07 am

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.

lrodrig
Posts: 17
Joined: Thu Sep 16, 2010 4:52 pm

Re: printing a backslash

Post by lrodrig » Mon Nov 29, 2010 8:28 am

Hello again:

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

Regards,
Luis.

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

Re: printing a backslash

Post by ramarren » Mon Nov 29, 2010 8:31 am

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.

lrodrig
Posts: 17
Joined: Thu Sep 16, 2010 4:52 pm

Re: printing a backslash

Post by lrodrig » Mon Nov 29, 2010 8:36 am

Hello,

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

Regards,
Luis.

Post Reply