Numbers
The numbers in Shen are as follows.
1. Numbers may be positive or negative or zero.
2. Numbers are either integers or floats; there are no rationals or complex numbers.
3. E number notation is allowed. They are not part of Kλ but are parsed by the Shen reader to
integers or floats.
4. +,-,/,* are 2-place and operate on floats and integers. / applied to two integers A and B
produces an integer if B is a divisor of A otherwise a float.
5. >=, <, <=, >, = operate over all numbers (> 3.5 3) is meaningful and true. (= 1 1.0) is true.
6. The maximum size of any integer or float and the precision of the arithmetic is implementation dependent.
The BNF is
<number> := <integer> | <float> | <e-number> | <sign> <number>
<integer> := <digit> | <digit> <integer>
<digit> := 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
<float> := <integer> . <integer> | . <integer>
<e-number> := <integer> e <integer> | <float> e <integer> | <integer> e -<integer> | <float> e -<integer>
<sign> := + | - | + <sign> | - <sign>
This is deliberately kept simple. There is no distinction between bignums, fixnums etc. There may be
packages which offer a richer range of types for numbers (fixnum and bignum etc.)
with much greater scope for optimisation within the compiler and which are platform specific. However
these will be plugins, not in the language standard or in the standard maths library.
Shen uses simple cancellation when reading signs; thus --3 is read as 3 and ---3 as -3. +3 is just 3.
Note (- 3)
returns a closure that subtracts its argument from 3. Any fronting number is treated as a token; so for instance
[f 5a] will be parsed as [f 5 a] (since 5a cannot be a symbol).
The maximum size of any number and the precision of the arithmetic are platform dependent. However the minimum
of double precision is strongly recommended.
For users running Shen on other platforms, it is highly likely that the platform has already defined >, +, -, *,
/, <, >=, =, etc. in a way that is inconsistent with the semantics allotted to these symbols in K&lambda. The .kl sources
use these symbols in their native dress because implementors wishing to implement Kλ will want to use '*' for
multiply etc. But platform providers compiling .kl sources to another language and who experience a name clash
with a native function, should read carefully the notes on porting in the porting document. |