Opened 2 years ago

Closed 2 years ago

#1572 closed defect (fixed)

read/write invariance of #! is violated

Reported by: Jim Ursetto Owned by:
Priority: major Milestone: 5.1
Component: core libraries Version: 5.0.0
Keywords: Cc:
Estimated difficulty: easy


In Chicken 5, read/write invariance of symbols beginning with #! is violated.

> (with-input-from-string
    (with-output-to-string (lambda () (write (string->symbol "#!abc")))) read)
Error: invalid `#!' token: “abc"

> (with-input-from-string
    (with-output-to-string (lambda () (write (string->symbol "#!")))) read)
Error: invalid `#!' token: “"

This causes a problem with chicken-doc, as there is a syntax entry called “#!” which is written out but cannot be read back in. In Chicken 4, this symbol is escaped when written out and reads back in fine.

This occurs because in Chicken 5, sym-is-readable? was changed:

commit 05f341e07a179ea95d891e5c55b2fe3d0dbe1ffe
Author: Evan Hanson <evhan@…>
Date: Wed Mar 14 17:53:00 2018 +1300

Print #!-style symbols verbatim, without pipes

These symbols are readable, so should be printed as-is by `##sys#print' just like #:keywords or the #!eof token.

 -                       ((and (eq? c #\#)
 -                            (not (eq? #\% (##core#inline "C_subchar" str 1))))
 -                       #f)
 +                      ((eq? c #\#) ;; #!rest, #!key etc
 +                       (eq? (##core#inline "C_subchar" str 1) #\!))

Unfortunately this assertion is incorrect: not all #! style symbols are readable, only valid #! style symbols such as #!rest. Other symbols are rejected by the reader. Furthermore, certain strange combinations, such as “(#! (foo bar))” result in an unterminated list, no matter how many close parens are added. The latter is the issue I am hitting.

The fix is probably to explicitly test for valid tokens, which appear to be only: “optional”, “rest” and “key”. Probably “eof” is ok as well—not 100% sure. The reader, of course, already tests for these exact tokens, so the writer should too.

Alas, chicken-doc won’t work with Chicken 5 until this is fixed — I worked around file locking bug #1565 in 5.0.0, but the writer bug is fatal.


Change History (2)

comment:1 Changed 2 years ago by sjamaan

Fixed with e9cf59f

comment:2 Changed 2 years ago by sjamaan

Milestone: someday5.1
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.