unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* 0e as identifier
@ 2010-01-02 12:45 Bill Schottstaedt
  2010-01-03 11:52 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Bill Schottstaedt @ 2010-01-02 12:45 UTC (permalink / raw)
  To: bug-guile

I believe r5rs says an identifier can't start with a digit, but
guile allows it to:

scheme@(guile-user)> (symbol? (make-symbol "0"))
#t
scheme@(guile-user)> (symbol->string (make-symbol "0"))
"0"
scheme@(guile-user)> (keyword? (symbol->keyword (string->symbol "0")))
#t
scheme@(guile-user)> (symbol? (string->symbol "0e0"))
#t

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.

(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").





^ permalink raw reply	[flat|nested] 3+ messages in thread

* 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

* Re: 0e as identifier
  2010-01-03 11:52 ` Andy Wingo
@ 2010-01-03 13:56   ` Bill Schottstaedt
  0 siblings, 0 replies; 3+ messages in thread
From: Bill Schottstaedt @ 2010-01-03 13:56 UTC (permalink / raw)
  To: Andy Wingo; +Cc: bug-guile

Right -- I realized just as I hit return that 1+ could go to 1+i, and
I like the name 1+, but it seemed kinda poltroonish to send a
complaint, then immediately say "oh forget it".  I can't decide
what the "right thing" is in this regard -- guile's choice is the best I
can come up with.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-03 13:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-02 12:45 0e as identifier Bill Schottstaedt
2010-01-03 11:52 ` Andy Wingo
2010-01-03 13:56   ` Bill Schottstaedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).