This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

printing a backslash

4 posts · 2940 views

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

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

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:
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

Hello,

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

Regards,
Luis.