lispcommon-lispgnu-common-lisp

How do I format a single backslash in common lisp?


I'm currently trying to get an output of ... \hline in GNU Common lisp 2.49, but I can't get the format to work. This is what I've tried so far to get a single backslash:

(format nil "\ ") => " "
(format nil "\\ ") => "\\ "
(format nil "\\\ ") => "\\ "

I thought that the double backslash would make it work, why isn't the backslash escaping just the other backslash?


Solution

  • Note the difference between creating a string and actually doing output to a stream:

    CL-USER 69 > (format nil "\\ ")
    "\\ "                               ; result
    
    CL-USER 70 > (format t "\\ ")
    \                                   ; output
    NIL                                 ; result
    
    CL-USER 71 > (format *standard-output* "\\ ")
    \                                   ; output
    NIL                                 ; result