[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: number syntax
> Date: Thu, 10 Jul 86 12:09 EDT
> From: Jonathan A Rees <JAR%ai.ai.mit.edu@CSNET-RELAY.ARPA>
>
> Date: Tue 17 Jun 86 16:00:31-CDT
> From: David Bartley <Bartley%ti-csl.csnet at CSNET-RELAY.ARPA>
>
> One irritant in the Report that we have neglected to comment on until
> now (sorry!) is the syntax of numbers. We believe that Scheme numbers
> are essentially equivalent to Common Lisp numbers except for the new
> notion of exactness. To the extent that that is so, it seems to be a
> (shudder!) ``gratuitous difference'' from Common Lisp to have an
> incompatible syntax. [...]
>
> What we'd like to see is an essential syntax for numbers which is
> compatible with Common Lisp's. Additional features, including
> exactness, would be optional extensions. Even so, they should not
> conflict with Common Lisp. For example, the use of `#s' and the order
> of <sign> and <prefix> are different in the two languages. [...]
>
> Does anyone agree with us? Is there time to make such a change before
> R^3RS goes to press?
>
>I think everyone agrees with you, and that there is time. Could you
>please write a concrete proposal, preferably something close to being
>suitable for inclusion in the report. Also please provide BNF. Thanks.
>
>Jonathan
Here's a stab at it---we expect and welcome debate over the details.
The major differences between the syntax of numbers in Common Lisp (CL)
and heretofore in Scheme (R^3RS) are:
(1) CL has the prefix denoting base precede the sign; R^3RS has the sign
precede the prefix, which includes the base specifier. I see no reason to
differ from CL.
(2) CL uses several exponent markers to specify levels of precision for
floating point numbers; R^3RS specifies precision levels (S and L) in the
prefix. Again, why differ from CL?
(3) CL does not provide for the use of `#' to indicate insignificant
digits. Making this a non-essential feature in R^3RS seems reasonable.
(4) CL provides only the #C(real real) notation for complex numbers; R^3RS
provides infix notations for both polar and rectangular forms. For
compatibility with CL, R^3RS should support the #C notation and the infix
forms should be non-essential extensions.
(5) CL integers may optionally terminate in a decimal point; R^3RS permits
such a number to be treated as floating point and it is debated whether it
is to be considered exact. This is a serious problem, since many
procedures are defined to accept only integer values. Is the call
(INTEGER->CHAR 55.) valid? We propose that this be a non-essential
feature in R^3RS.
(6) CL integers and ratios are not permitted to have exponent markers.
This feature should be a non-essential extension to Scheme.
(7) CL does not have the concept of exactness. Most (all?) existing
implementations of Scheme do not support this feature, so it should be
non-essential.
We propose the following syntax for numbers in Scheme. (Recall that
letter case is insignificant in the grammar and that the rules for <ureal
R>, <prefix R>, etc., should be replicated for R = 2, 8, 10, and 16.)
<number> --> <real> | #c( <real> <real> )
<real> --> <prefix R> <sign> <ureal R>
<prefix R> --> <exactness> <radix R>
<exactness> --> <empty> | #i | #e
<radix 2> --> #b
<radix 8> --> #o
<radix 10> --> <empty> | #d
<radix 16> --> #x
<sign> --> <empty> | + | -
<ureal R> --> <integer R> | <ratio R> | <flonum R>
<integer R> --> <digit R>+ #*
<ratio R> --> <digit R>+ #* / <digit R>+ #*
<flonum R> --> . <digit R>+ #* <expon>
| <digit R>+ . <digit R>* #* <expon>
| <digit R>+ #* . #* <expon>
<expon> --> <empty> | <expon-marker> <sign> <digit>+
<expon-marker> --> e | f | d | l | s
<digit 2> --> 0 | 1
<digit 8> --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
<digit 10> --> <digit 8> | 8 | 9
<digit 16> --> <digit 10> | a | b | c | d | e | f
Although we have incorporated <exactness> and the use of `#' above, they
should be stated to be non-essential features of Scheme.
Nonessential feature: integers with optional decimal points.
<integer R> --> <digit R>+ #* .
Nonessential feature: integers and ratios with exponents.
<integer R> --> <digit R>+ #* <expon>
<ratio R> --> <digit R>+ #* <expon> / <digit R>+ #* <expon>
Nonessential number productions representing complex numbers. We worry
that the forms <real>+<ureal>i and <real>-<ureal>i can be hard to parse.
Perhaps combining the suffix `i' with the infix `+' or `-' would be
palatable to those who want this feature.
<number> --> <real> +i <ureal>
| <real> -i <ureal>
| <real> @ <real>
Regards,
David Bartley
Mark Meyer
-------
- Follow-Ups:
- Re: number syntax
- From: willc%tekchips.tek.csnet@CSNET-RELAY.ARPA
- numbers
- From: willc%tekchips.tek.csnet@CSNET-RELAY.ARPA