This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Numbers in Kawa
On 04/27/2012 02:05 PM, Jamison Hope wrote:
That does seem erroneous. I feel like (string-ref "abc" 1.0) should work,
though [with a warning], so perhaps it should be an error iff the float
isn't already integer-valued?
RnRS does require the index to be an exact non-negative integer,
so does not allow this.
Worse, the numeric conversions aren't consistent. IMHO if you can convert
to an int, you should be able to convert to an integer, too.
I agree.
#|kawa:1|# (as int 10.0)
/dev/stdin:1:9: warning - saw float where int expected
10
#|kawa:2|# (integer? 10.0)
#t
#|kawa:3|# (as integer 10.0)
/dev/stdin:3:13: warning - type DFloNum is incompatible with required
type integer
/dev/stdin:3:1: warning - cannot convert literal (of type
gnu.math.DFloNum) to Type integer
I agree this is a bug. Part of the problem is that Kawa doesn't
distinguish between implicit and explicit type conversions. This
should be fixed, though working out the exact rules is a bit tricky.
(I wrote a proposal for what to do in an old email, but I don't
remember the specifics.)
I.e. I think converting float/double to int or integer is ok
when the conversion is explicit, but not when the conversion is
implicit (as in wrong argument type).
--
--Per Bothner
per@bothner.com http://per.bothner.com/