#183 closed defect (fixed)
symbols starting with # do not have read-write invariance
Reported by: | Jim Ursetto | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | core libraries | Version: | 4.3.x |
Keywords: | Cc: | felix winkelmann | |
Estimated difficulty: |
Description
I noticed this because if I have a string "#hostinfo#" and do string->symbol on it and write it to a file, (read) on this file causes a syntax error.
I am not sure, but at first glance you might fix this by changing
(not (##core#inline "C_substring_compare" "#!" str 0 0 2))
to
(not (##core#inline "C_substring_compare" "#" str 0 0 1))
or a more efficient equivalent in sym-is-readable? in library.scm. As far as I know, anything starting with # is sharp-syntax and is unlikely to be read as a symbol. Yes?
Examples:
#;> (with-input-from-string (with-output-to-string (lambda () (write (string->symbol "#x")))) read) Error: illegal number syntax: "" #;> (with-input-from-string (with-output-to-string (lambda () (write (string->symbol "#hostinfo")))) read) Error: invalid sharp-sign read syntax: #\h #;> (symbol? (with-input-from-string (with-output-to-string (lambda () (write (string->symbol "#t")))) read)) #f #;> (char? (with-input-from-string (with-output-to-string (lambda () (write (string->symbol "#\\x")))) read)) #t
Change History (6)
comment:1 follow-up: 3 Changed 15 years ago by
comment:2 follow-up: 4 Changed 15 years ago by
Replying to zbigniew:
As far as I know, anything starting with # is sharp-syntax and is unlikely to be read as a symbol. Yes?
What about ##sys#foo
?
comment:3 Changed 15 years ago by
Replying to zbigniew:
I mean, I know this is not guaranteed by R5RS and I should maybe store this data as strings instead of symbols, but it seems that (string->symbol "#x") should generate |#x| not throw an error in Chicken to be consistent.
(string->symbol
doesn't throw an error, it's the reader that complains)
It would probably be better to handle this, yes.
comment:4 Changed 15 years ago by
comment:5 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
See commit 3f304513c1a678fccdae3119f4ead3e27b048d5b (experimental branch).
Note that only symbols starting with #
are escaped, since internal module-scope aliases like foo#bar
should be printed unescaped.
I mean, I know this is not guaranteed by R5RS and I should maybe store this data as strings instead of symbols, but it seems that (string->symbol "#x") should generate |#x| not throw an error in Chicken to be consistent.