From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Using the GNU GMP Library for Bignums in Emacs Date: Mon, 09 Jul 2018 23:41:50 -0400 Message-ID: References: <29f933ac-a6bf-8742-66a7-0a9d6d3e5a88@disroot.org> <83bmecy6fx.fsf@gnu.org> <0d3175d8-d996-651e-b221-71978bde3a65@cs.ucla.edu> <87tvpdnzgy.fsf@tromey.com> <4c2a814f-c254-29e5-39cf-11b5f2e5c9c8@cs.ucla.edu> <49d8ba62-c9a5-9203-d882-8e900b441ff3@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1531194042 17922 195.159.176.226 (10 Jul 2018 03:40:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 10 Jul 2018 03:40:42 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 10 05:40:38 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fcjW0-0004XP-9e for ged-emacs-devel@m.gmane.org; Tue, 10 Jul 2018 05:40:36 +0200 Original-Received: from localhost ([::1]:45606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcjY5-0006tp-Ak for ged-emacs-devel@m.gmane.org; Mon, 09 Jul 2018 23:42:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcjXR-0006tk-AA for emacs-devel@gnu.org; Mon, 09 Jul 2018 23:42:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcjXO-00072k-7A for emacs-devel@gnu.org; Mon, 09 Jul 2018 23:42:05 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:40402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcjXO-000729-26 for emacs-devel@gnu.org; Mon, 09 Jul 2018 23:42:02 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w6A3fox9008131; Mon, 9 Jul 2018 23:41:50 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 4964F661B8; Mon, 9 Jul 2018 23:41:50 -0400 (EDT) In-Reply-To: <49d8ba62-c9a5-9203-d882-8e900b441ff3@cs.ucla.edu> (Paul Eggert's message of "Mon, 9 Jul 2018 16:25:24 -0700") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6325=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6325> : inlines <6744> : streams <1792103> : uri <2671266> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:227196 Archived-At: >> Also, for purposes of cl-generic's dispatch it'd be better for type-of >> to return `natnum` or `fixnum` when applicable. > Isn't the issue of how finely type-of distinguishes integers separable from > the issue of whether to have bignums? type-of could return 'natnum' now, > even without bignums, but it doesn't. Exactly. I was pointing out that type-of already provides suboptimal results in this respect, but also that there's some grey area when it comes to decide what it should return. The main problem is due to subtyping: natnum is (currently) a subtype of fixnum which is a subtype of integer, so 5 is all three at the same time and hence (type-of 5) could return any of those three and claim to be correct. In general, we'd want type-of to return the "most precise" type, so you could argue that `natnum` is the better option. Note that `natnum` is not a valid type in CommonLisp, tho, so `fixnum` would probably be a better option (especially if you want to consider positive bignums as natnums, in which case natnum is not a subtype of fixnum). > If we decide that type-of should return some value other than > 'integer' for some integers, how would we decide what value to return? > For example, if (natnump X) and (bignump X) both succeed, should > type-of return 'natnum' or 'bignum' or both? Based on the above (the fact that natnum is neither a subtype nor a supertype of fixnum or bignum, and the fact that it's not even a type in Common Lisp), I think we can ignore `natnum` for `type-of` purposes. > All in all I expect Elisp would be a bit easier to use and explain if it > treats 'integer' as the fundamental type, and 'characterp', 'fixnump', > 'bignump', 'natnump' as predicates that succeed on only some members of > that type. As long as `eq` treats bignums differently from fixnums, I think type-of should return different values for the two (ideally, I'd vote for `bignum` and `fixnum` respectively). When/if we completely hide the difference between the two (i.e. all integers behave like bignums and fixnums are just an implementation detail for optimization purposes), then I'd agree that `type-of` can return just `integer` for those numbers regardless of their internal representation. But at that moment I'd also argue that `fixnump` and `bignump` should disappear. >> it's indeed safer to just keep returning `integer` for small integers >> (and probably some other value for bignums, such as `bignum`). > Why the latter? That is, when would it be useful in existing code for > (type-of X) to return a value other than 'integer' when (integerp X) > returns t? Because it's generally better to return a more precise type than a more generic one. E.g. (type-of '(1 2)) returns `cons` not `list` and (type-of [1 2]) returns `vector` rather than `sequence`. Stefan