* Re: 0e as identifier
2010-01-02 12:45 0e as identifier Bill Schottstaedt
@ 2010-01-03 11:52 ` Andy Wingo
2010-01-03 13:56 ` Bill Schottstaedt
0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2010-01-03 11:52 UTC (permalink / raw)
To: Bill Schottstaedt; +Cc: bug-guile
Hi Bill,
On Sat 02 Jan 2010 13:45, "Bill Schottstaedt" <bil@ccrma.Stanford.EDU> writes:
> I believe r5rs says an identifier can't start with a digit, but
> guile allows it to
What R5RS says is this:
The precise rules for forming identifiers vary among implementations
of Scheme, but in all implementations a sequence of letters, digits,
and "extended alphabetic characters" that begins with a character
that cannot begin a number is an identifier.
Thus the following identifier is not prohibited by R5RS, but is not
portable:
scheme@(guile-user)> 1+
$1 = #<primitive-procedure 1+>
> which leads one naively to:
>
> scheme@(guile-user)> (let ((0e 1)) 0e)
> 1
> scheme@(guile-user)> (let ((0e0 1)) 0e0)
> <error printout>
>
> Not a bug, I guess, but not very pretty.
Right. What Guile does is that if a token starts with a digit, it tries
to parse the token as a number, but if it's not a syntactically valid
number it returns a symbol instead.
static SCM
scm_read_number (scm_t_wchar chr, SCM port)
{
SCM result;
SCM buffer;
size_t read;
scm_ungetc (chr, port);
buffer = read_complete_token (port, &read);
result = scm_string_to_number (buffer, SCM_UNDEFINED);
if (!scm_is_true (result))
/* Return a symbol instead of a number. */
result = scm_string_to_symbol (buffer);
return result;
}
> (r6rs says an identifier "begins with a character that cannot
> begin a representation of a number object." I think they meant
> "a sequence of characters").
R6RS is a prescriptivist standard :)
I don't think Guile will ever raise errors in *all* cases specified by
the R6RS. This is probably one of them, although a reader option might
be useful in some cases.
Glad to see you're trying out the 1.9 series. Please let us know how it
goes!
Regards,
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 3+ messages in thread