Re: reading/writing strings

RT Happe <[email protected]> Sun, 4 Nov 2012 12:22:44 +0100
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <[email protected]>
Heath Putnam 2012-11-04:
> 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
with a quote character like so:

  > "'"
  "'"
  > "\'"
  "'"

Heath Putnam 2012-11-04:
> 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