Space character printed readably in bad way
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
The space character in SBCL is printed in readable representation as "#\ ", i.e., putting out the space character after the "#\" pair of characters. There are better alternatives: #\sp and #\space
This is first of all very inconvenient in that the character cannot be easily seen in most circumstances. E.g., you cannot tell if it's a space or a tab or some other invisible character or possibly just "#\" followed by nothing.
The biggest problem happens when this printed representation interacts with the pretty printer. When printing a list of characters, for example, the pretty printer does a sort of "word wrapping" on the output such that any whitespace type character at the end of a line is simply eliminated. If you then, say, copy/paste the resulting output, the space characters that happened to be printed at the end of lines lose their original value, typically becoming #\newline characters.
Example in REPL with *print-pretty* = T:
> CL-USER> (progn (print (concatenate 'list (make-list 30 :initial-element #\space))) t)
> (#\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\
> #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ )
> T
Note that the end of the first line of output has no space before the linebreak.
Now copy the first two lines of output. Then type single quote (') and then paste:
> CL-USER> '(#\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\
> #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ )
> (#\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\
> #\Newline #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ #\ )
Note that the character corresponding to the previous last space on the first line is now a #\Newline character.
A good solution would be to have the default printed output representation be one that uses multiple actual visible glyphs, e.g., #\space or #\sp. This is, by the way, more consistent with with the handling of tab, newline, and return. Space is handled in an inconsistent manner with respect to those characters. E.g.,
> CL-USER> #\tab
> #\Tab
> CL-USER> #\newline
> #\Newline
> CL-USER> #\return
> #\Return
> CL-USER> #\space
> #\
SBCL Version: SBCL 2.2.6
uname -a
Darwin mhd-mac-
Changed in sbcl: | |
status: | New → Fix Committed |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
Yes, but...
CLHS 13.1.4.1 says "A graphic character is one that has a standard textual representation as a single glyph, such as A or * or =. Space, which effectively has a blank glyph, is defined to be a graphic." (It also clarifies that Tab, Newline and Return are non-graphic.)
CLHS 22.1.3.2 says "For the graphic standard characters, the character itself is always used for printing in #\ notation---even if the character also has a name[5]."
I agree that the interaction between these two issues is awkward. Regarding the further interaction with *print-pretty*, possibly our initial pprint- dispatch- table should have an entry to make #\Space print as #\Space: I don't think that there's anything that would disallow that.