Re: (vector-set! bucket (truncate x) y)
>Indeed
>
> STk> (real? (truncate 5.3))
> #t
>
>So, truncate isn't returning an integer.
That is a misconception about how numbers behave in Scheme. In
particular,
> (integer? 1.0)
#t
> (real? 1)
#t
In the first case, 1.0 is clearly an integer because its fractional part
is zero. In the second case, 1 is clearly real because its imaginary
part is zero.
One distinction Scheme makes is based on the notion of exactness: only
exact integers can be used to index into vectors. 1.0 is an inexact
integer; 1 is an exact integer. TRUNCATE returns an integer, but the
result is inexact if the argument is inexact. Conversely the result is
exact if the argument is exact:
> (truncate 3/2)
1
The procedure inexact->exact is used to convert inexact numbers to
exact numbers, eg
> (inexact->exact 1.5)
3/2
The Report discusses the distinctions and the numeric tower in detail;
it isn't something one 'gets' immediately but it is necessary to study
it to understand how numbers work in Scheme.
(Those examples may or may not work that way in STk, which may not
have exact rational numbers (fractions)).
--lars
Received on Sat Aug 12 2000 - 03:12:53 CEST
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST