From: Coby Beck
Subject: changing read's string delimiter
Date: 
Message-ID: <SNn17.112439$_T2.25761288@typhoon.tampabay.rr.com>
I am using LispWorks 4.1 and defined the following:

(defun read-single-quoted-string (stream)
  (let ((*readtable* (copy-readtable)))
    (set-syntax-from-char #\' #\")
    (read stream)))

As the following session shows, it is not doing what its name implies:

CL-USER 84 > (setf foo-input (make-string-input-stream "2 'hey, this is a
string!' 15:30:55:345 45 \"text\""))
#<SYSTEM::STRING-INPUT-STREAM 203FE72C>

CL-USER 85 > (read in)
2

CL-USER 86 > (read-single-quoted-string in)
"hey, this is a string!' 15:30:55:345,45,"

What am I missing?

Coby

actually, I just tried the same in ACL and it met my expectations....

From: Barry Margolin
Subject: Re: changing read's string delimiter
Date: 
Message-ID: <Z1o17.95$on2.2159@burlma1-snr2>
In article <·························@typhoon.tampabay.rr.com>,
Coby Beck <·····@mercury.bc.ca> wrote:
>I am using LispWorks 4.1 and defined the following:
>
>(defun read-single-quoted-string (stream)
>  (let ((*readtable* (copy-readtable)))
>    (set-syntax-from-char #\' #\")
>    (read stream)))
>
>As the following session shows, it is not doing what its name implies:
>
>CL-USER 84 > (setf foo-input (make-string-input-stream "2 'hey, this is a
>string!' 15:30:55:345 45 \"text\""))
>#<SYSTEM::STRING-INPUT-STREAM 203FE72C>
>
>CL-USER 85 > (read in)
>2
>
>CL-USER 86 > (read-single-quoted-string in)
>"hey, this is a string!' 15:30:55:345,45,"
>
>What am I missing?

The description of the double quote character says "Successive characters
are read ... until another double quote is encountered."  It doesn't say
"until another character with the same syntax as double quote is
encountered" or "until the same character that introduced the string is
encountered."

So the typical implementation of the double quote macro could be something
like:

(defun double-quote-reader (stream char)
  (declare (ignore char)) ;; We don't care what character introduced it
  (coerce
    (loop for char = (read-char stream)
          when (single-escape-p char)
          do (setq char (read-char stream))
          until (char= char #\")
          collect char)
    'simple-string))

Similarly, if you were to copy the syntax of ( to {, you could write a list
as {foo bar baz), but it wouldn't allow {foo bar baz}, because the ( macro
character looks specifically for ) as the terminator.

>actually, I just tried the same in ACL and it met my expectations....

Sounds like someone there has an unusual interpretation of "another double
quote".

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Coby Beck
Subject: Re: changing read's string delimiter
Date: 
Message-ID: <Moo17.112654$_T2.25786831@typhoon.tampabay.rr.com>
"Barry Margolin" <······@genuity.net> wrote in message
······················@burlma1-snr2...
> In article <·························@typhoon.tampabay.rr.com>,
> Coby Beck <·····@mercury.bc.ca> wrote:
> >I am using LispWorks 4.1 and defined the following:
> >
> >(defun read-single-quoted-string (stream)
> >  (let ((*readtable* (copy-readtable)))
> >    (set-syntax-from-char #\' #\")
> >    (read stream)))
> >
> >As the following session shows, it is not doing what its name implies:
> >
> >CL-USER 84 > (setf foo-input (make-string-input-stream "2 'hey, this is a
> >string!' 15:30:55:345 45 \"text\""))
> >#<SYSTEM::STRING-INPUT-STREAM 203FE72C>
> >
> >CL-USER 85 > (read in)
> >2
> >
> >CL-USER 86 > (read-single-quoted-string in)
> >"hey, this is a string!' 15:30:55:345,45,"
> >
> >What am I missing?
>
> The description of the double quote character says "Successive characters
> are read ... until another double quote is encountered."  It doesn't say
> "until another character with the same syntax as double quote is
> encountered" or "until the same character that introduced the string is
> encountered."
>


Hmm..you're right about that quote, but I was reading under
SET-SYNTAX-FROM-CHAR

"A macro definition from a character such as " can be copied to another
character; the standard definition for " looks for another character that is
the same as the character that invoked it. The definition of ( can not be
meaningfully copied to {, on the other hand. The result is that lists are of
the form {a b c), not {a b c}, because the definition always looks for a
closing parenthesis, not a closing brace. "

Maybe the Spec is miss quoting itself here, but I must say I prefer ACL's
more intuitive result.  Of course it is mere coincidence that it would also
make my job a bit easier right now...



Coby


--
(remove #\space "coby . beck @ opentechgroup . com")
From: Barry Margolin
Subject: Re: changing read's string delimiter
Date: 
Message-ID: <EQo17.96$on2.1966@burlma1-snr2>
In article <·························@typhoon.tampabay.rr.com>,
Coby Beck <·····@mercury.bc.ca> wrote:
>Hmm..you're right about that quote, but I was reading under
>SET-SYNTAX-FROM-CHAR
>
>"A macro definition from a character such as " can be copied to another
>character; the standard definition for " looks for another character that is
>the same as the character that invoked it. The definition of ( can not be
>meaningfully copied to {, on the other hand. The result is that lists are of
>the form {a b c), not {a b c}, because the definition always looks for a
>closing parenthesis, not a closing brace. "
>
>Maybe the Spec is miss quoting itself here, but I must say I prefer ACL's
>more intuitive result.  Of course it is mere coincidence that it would also
>make my job a bit easier right now...

I would say that the spec is contradicting itself.  The description under
SET-SYNTAX-FROM-CHAR seems more intuitive and often the behavior one wants,
and perhaps it was even the original intent, but I don't think that's the
right way to resolve the contradiction.  I think that the section that
specifically describes the behavior of each macro character should have
precedence over another section that merely uses it as an example.

On the other hand, perhaps the use of the word "another" in the description
of double quote's behavior is intended to imply that the terminating
character should be another instance of the initiating character.  It only
says "double quote" there because that's the usual initiating character.
The read macro mechanism certainly makes it easy for a macro to operate
this way, since the initiating character is passed as an argument (although
most reader macros ignore it).

Unfortunately, doublequote is the only character that's used to start and
end the syntax of something, so it's not possible to argue that it should
be consistent with other, similar macro characters.  You might suggest
|...| as an analogy, but that differs in a few significant ways: 1) it's
not a macro character, it's part of the syntax of extended tokens, and 2)
the specification of the token reader carefully refers to "single escape"
and "multiple escape" characters, rather than specific character names
(backslash and vertical bar).  This suggests that escaping is intended to
apply to character classes, while string termination only applies to a
specific character.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.