Skip to content

Commit f01e8b5

Browse files
author
Ken Raeburn
committed
Better fix for printing comma expressions.
The print-symbols-as-references processing for comma and related symbols works fine if they're being printed out as normal symbols. It's only in the special ",foo" style syntax where using "#N=" is likely to break things, because "#1=,foo" reads back as setting #1# to ,foo rather than to just the comma symbol. * src/print.c (print_object): When printing "," or related symbols with special syntax, don't use print_object on the special symbol itself. (PRINT_CIRCLE_CANDIDATE_P): Revert previous change.
1 parent 9919e41 commit f01e8b5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/print.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,7 @@ print (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
11511151
&& ! NILP (Vprint_gensym)) \
11521152
|| (SYMBOLP (obj) \
11531153
&& SYMBOL_INTERNED_P (obj) \
1154-
&& ! NILP (Vprint_symbols_as_references) \
1155-
&& ! EQ (Qcomma, obj) \
1156-
&& ! EQ (Qcomma_at, obj) \
1157-
&& ! EQ (Qcomma_dot, obj)))
1154+
&& ! NILP (Vprint_symbols_as_references)))
11581155

11591156
/* Construct Vprint_number_table according to the structure of OBJ.
11601157
OBJ itself and all its elements will be added to Vprint_number_table
@@ -1607,7 +1604,20 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
16071604
|| EQ (XCAR (obj), Qcomma_at)
16081605
|| EQ (XCAR (obj), Qcomma_dot)))
16091606
{
1610-
print_object (XCAR (obj), printcharfun, false);
1607+
/* If print-symbols-as-references is enabled, symbols may
1608+
print with "#N=" or "#N#" form. When we print a cons
1609+
cell with parens and separated elements, that's fine, but
1610+
for comma symbols we depend on the reader to generate the
1611+
cons cell from the special syntax. The Lisp reader will
1612+
treat "#1=,#2=foo" as setting reference 1 to ",foo", not
1613+
to ",", so we can't use print_object to print out the
1614+
comma symbols without breaking the ability to read the
1615+
result back properly. */
1616+
printchar (',', printcharfun);
1617+
if (EQ (XCAR (obj), Qcomma_at))
1618+
printchar ('@', printcharfun);
1619+
else if (EQ (XCAR (obj), Qcomma_dot))
1620+
printchar ('.', printcharfun);
16111621
new_backquote_output--;
16121622
print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
16131623
new_backquote_output++;

0 commit comments

Comments
 (0)