bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 0e as identifier


From: Andy Wingo
Subject: Re: 0e as identifier
Date: Sun, 03 Jan 2010 12:52:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Hi Bill,

On Sat 02 Jan 2010 13:45, "Bill Schottstaedt" <address@hidden> 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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]