emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using the GNU GMP Library for Bignums in Emacs


From: Stefan Monnier
Subject: Re: Using the GNU GMP Library for Bignums in Emacs
Date: Tue, 10 Jul 2018 16:33:35 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> If so, why would someone want to specialize a method just for fixnums, as
> opposed to a method for integers?

cl-generic has no trouble dispatching on a supertype of that returned by
`type-of`.   IOW if `type-of` returns `fixnum` and `bignum` cl-generic
has no difficulty finding that these are applicable for methods that
stipulate an `integer` argument (or a `number` argument for that
matter).  But the other way around is a lot more difficult, so as long
as fixnums and bignums are visibly two different types, I think it makes
more sense for `type-of` to return different values for those two cases.

> The basic operations +, -, * etc. aren't specialized for fixnums.

Actually, they are, but this is done by manual type-testing in the
C code, not with cl-defmethod.

> Are you anticipating adding specialized variants fixnum-+, fixnum--,
> fixnum-*, etc., and then having people write methods with all this in
> mind? Or maybe having the bytecode optimizer use them?

Not at all, no.

> If not, then I'm still not following the advantage of having (type-of 5)
> return something other than 'integer'.

For backward compatibility reasons, I agree that (type-of 5) should
continue returning `integer` (tho returning `fixnum` would be better
otherwise), but (type-of <BIGNUM>) doesn't suffer from such a backward
compatibility requirement, so it would be preferable for it to return
`bignum`.

I wonder on the other hand, why you think it'd be bad for (type-of <BIGNUM>)
to return `bignum` instead of `integer`.


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]