Summary

symbols starting with # do not have read-write invariance

Metadata

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

Changes and comments

[2010-03-05 08:54:40 UTC] zbigniew wrote:

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.

[2010-03-05 10:58:57 UTC] felix wrote:

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`?

[2010-03-05 10:59:57 UTC] felix wrote:

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.

[2010-03-05 11:04:58 UTC] felix wrote:

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.

[2010-03-05 12:24:32 UTC] felix changed status from new to closed

[2010-03-05 12:24:32 UTC] felix set resolution to fixed

[2010-03-05 12:24:32 UTC] felix wrote:

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.

[2010-03-11 10:33:12 UTC] Milestone 4.4.0 deleted