Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#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 Changed 14 years ago by Jim Ursetto

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.

comment:2 in reply to:  description ; Changed 14 years ago by felix winkelmann

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 in reply to:  1 Changed 14 years ago by felix winkelmann

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 in reply to:  2 Changed 14 years ago by felix winkelmann

Replying to felix:

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?

Nevermind. It's handled elsewhere.

comment:5 Changed 14 years ago by felix winkelmann

Resolution: fixed
Status: newclosed

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.

comment:6 Changed 14 years ago by (none)

Milestone 4.4.0 deleted

Note: See TracTickets for help on using tickets.