You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The question is whether the Lisp printer should escape characters that the Lisp reader doesn't need to be escaped. In particular, if a symbol contains a non-terminating macro character in the middle or at the end of the symbol's name, PRIN1 escapes either that character or sometimes the whole symbol, even though it doesn't need to. E.g., in an environment where *PRINT-ESCAPE* is true, *PRINT-READABLY* is true, *PRINT-CASE* is :UPCASE, and (READTABLE-CASE *READTABLE*) is :UPCASE, we have this:
? 'A#B
|A#B|
? 'MID#DLE
MID\#DLE
? 'END#
END\#
It's not that the result is wrong, but it can be ... annoying. (I discovered this when I defined ? as a non-terminating macro character, so that when the reader sees ?LEFT, it calls the reader macro function for ? but when reading MID?DLE or RIGHT?, it does not. I like to define predicates with names like VALID?, but PRIN1 prints that as VALID\?, which is ... annoying.) After all, it's legal for PRIN1 to print the symbol CAR as |CAR| or \C\A\R, but no one would expect (or tolerate) that.
I don't know how (PRIN1 symbol), i. e., (WRITE symbol :ESCAPE T), is implemented, but in addition to checking the value of *PRINT-CASE* and *PRINT-READABLY*, it must be looking at (GET-MACRO-CHARACTER character *READTABLE*) for every character in the symbol's name to see whether its syntax type is anything other than constituent. If the syntax type is non-terminating macro, and the character is not the first one in the symbol's name, then there is no need to escape it. But it does.
The text was updated successfully, but these errors were encountered:
The Common Lisp Hyperspec says, "The Lisp reader cannot accept as input everything that the Lisp printer produces, and the Lisp reader has features that are not used by the Lisp printer."
The question is whether the Lisp printer should escape characters that the Lisp reader doesn't need to be escaped. In particular, if a symbol contains a non-terminating macro character in the middle or at the end of the symbol's name,
PRIN1
escapes either that character or sometimes the whole symbol, even though it doesn't need to. E.g., in an environment where*PRINT-ESCAPE*
is true,*PRINT-READABLY*
is true,*PRINT-CASE*
is:UPCASE
, and(READTABLE-CASE *READTABLE*)
is:UPCASE
, we have this:It's not that the result is wrong, but it can be ... annoying. (I discovered this when I defined
?
as a non-terminating macro character, so that when the reader sees?LEFT
, it calls the reader macro function for?
but when readingMID?DLE
orRIGHT?
, it does not. I like to define predicates with names likeVALID?
, butPRIN1
prints that asVALID\?
, which is ... annoying.) After all, it's legal forPRIN1
to print the symbolCAR
as|CAR|
or\C\A\R
, but no one would expect (or tolerate) that.I don't know how
(PRIN1 symbol)
, i. e.,(WRITE symbol :ESCAPE T)
, is implemented, but in addition to checking the value of*PRINT-CASE*
and*PRINT-READABLY*
, it must be looking at(GET-MACRO-CHARACTER character *READTABLE*)
for every character in the symbol's name to see whether its syntax type is anything other than constituent. If the syntax type is non-terminating macro, and the character is not the first one in the symbol's name, then there is no need to escape it. But it does.The text was updated successfully, but these errors were encountered: