Discussion:
reading/writing strings
Heath Putnam
2012-11-04 08:38:00 UTC
Permalink
If you type "'" at the command line, the system writes back "\'".
If you type "\'" in, the system fails, because read doesn't expect #\'
to be escaped.

The relevant code is in scheme/rts/{read|write}.scm

I changed decode-escape in scheme/rts/read.scm to read #\' the way it
reads #\\, rebuilt my system and now I can read the output of write
even when the strings include #\'.

I was fairly certain that read and write would be inverses of each
other (w.r.t. strings), so now I'm wondering if my fix was correct, or
if I'm misunderstanding things and have actually made things less
correct.

Heath
RT Happe
2012-11-04 11:22:44 UTC
Permalink
Post by Heath Putnam
If you type "'" at the command line, the system writes back "\'".
If you type "\'" in, the system fails, because read doesn't expect #\'
to be escaped.
S48 0.36 (or at least scsh 0.6 where I tried this) reads and writes strings
Post by Heath Putnam
"'"
"'"
Post by Heath Putnam
"\'"
"'"
Post by Heath Putnam
I changed decode-escape ... to read #\' the way it reads #\\,
I was fairly certain that read and write would be inverses of each
other (w.r.t. strings), so now I'm wondering if my fix was correct,
As far as the R5RS goes, "Scheme does not specify the effect of a backslash
within a string that is not followed by a doublequote or backslash."
--> section 6.3.5 Strings.

As for the inverse relation of READ and WRITE, the R5RS indicates just that
in section 3.3 External representations

The procedure READ (section 6.6.2) parses external representations,
and the procedure WRITE (section 6.6.3) generates them. Together,
they provide an elegant and powerful input/output facility.

but then goes on in section 6.6.3 Output

library procedure: (write obj)
library procedure: (write obj port)
Writes a written representation of OBJ to the given port.
Strings that appear in the written representation
are enclosed in doublequotes, and within those strings
backslash and doublequote characters are escaped by backslashes.

Now "a written representation" is far less explicit
than I would wish it to be (for objects with an external representation),
but in any case, the lexical syntax of string datums simply says
that a string datum begins and ends with a doublequote
and may contain any character but " and \; cf. sections 7.1.2+7.1.1.


rt
Michael Sperber
2012-11-04 12:49:30 UTC
Permalink
Post by Heath Putnam
If you type "'" at the command line, the system writes back "\'".
If you type "\'" in, the system fails, because read doesn't expect #\'
to be escaped.
Bug. But you're using 1.8, right? This is fixed in the development
code (which had a number of write/read invariance errors), where "'"
prints as "'".
--
Regards,
Mike
Taylor R Campbell
2012-11-04 15:29:07 UTC
Permalink
Date: Sun, 4 Nov 2012 01:38:00 -0700
From: Heath Putnam <***@gmail.com>

If you type "'" at the command line, the system writes back "\'".
If you type "\'" in, the system fails, because read doesn't expect #\'
to be escaped.

Sounds like a relatively recent bug (OK, I guess 1.3 is pretty old
now):

Welcome to Scheme 48 1.3 (made by riastradh on Fri Jun 10 14:06:31 UTC 2011)
Copyright (c) 1993-2005 by Richard Kelsey and Jonathan Rees.
Please report bugs to scheme-48-***@s48.org.
Get more information at http://www.s48.org/.
Type ,? (comma question-mark) for help.
"'"
"'"
Jonathan Rees
2012-11-04 18:36:03 UTC
Permalink
I believe I reported this bug a few years back. Mike S said he had fixed it, and the fix is in the source code repository.
http://www.s48.org/internal/development.html

Scheme 48 has the opposite philosophy of Postel's law, and tries to be conservative in what it accepts, i.e. to reject as many unportable programs as possible (except when you 'step outside the box' and use ,-commands). This would suggest that \' in a string should be an error.

Best
Jonathan
Post by Taylor R Campbell
Date: Sun, 4 Nov 2012 01:38:00 -0700
If you type "'" at the command line, the system writes back "\'".
If you type "\'" in, the system fails, because read doesn't expect #\'
to be escaped.
Sounds like a relatively recent bug (OK, I guess 1.3 is pretty old
Welcome to Scheme 48 1.3 (made by riastradh on Fri Jun 10 14:06:31 UTC 2011)
Copyright (c) 1993-2005 by Richard Kelsey and Jonathan Rees.
Get more information at http://www.s48.org/.
Type ,? (comma question-mark) for help.
"'"
"'"
Loading...