Email list hosting service & mailing list manager


Re: meta-comment on typing bear 16 Oct 2005 19:37 UTC


On Thu, 6 Oct 2005, Marcin 'Qrczak' Kowalczyk wrote:

>Per Bothner <xxxxxx@bothner.com> writes:
>
>> Since it *optional* static typing, I'm assuming that the specific
>> operations are "consistent" in the sense of the following example:
>>
>> If (and (fixnum? x) (fixnum? y))
>> then: (eqv? (+ x y) (fx+ x y))
>
>It's not the same: (fx+ x y) returns a fixnum even if it overflows.

I think the consistency Per was asking about (correct me if
I'm wrong) might be more completely expressed as:

If (and (fixnum? x) (fixnum? y) (fixnum? (+ x y)))
Then (eqv? (+ x y) (fx+ x y)

Because +, even on integer-only arguments, has to deal with several
possibilities:

   Case 1: one or more arguments are bignums, but the result is fixnum.
           example: (+ (! 1000) (* (! 1000) -1))

   Case 2: one or both arguments are bignums and the result is bignum.
           example: (+ (! 1000) (! 1000))

   Case 3: both arguments are fixnum but the result is bignum.
	   example: (+ MAXFIXNUM 22)

   Case 4: both arguments are fixnum and the result is also fixnum.
	   example: (+ 22 0)

fx+, as I understand it, is specified to give the same results
as + only in case 4.  Calling fx+ in cases 1,2,3 would be an error
and result in unspecified behavior.

				Bear