From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Playing cards. Date: Mon, 28 Mar 2016 16:13:16 -0500 Organization: JSA Research & Innovation Message-ID: References: <72436e28-13a7-4580-9503-0bd7111f4bab@googlegroups.com> <060566e9-c555-4eee-a40d-8ed338643d9e@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1459199597 25162 24.196.82.226 (28 Mar 2016 21:13:17 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 28 Mar 2016 21:13:17 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:29913 Date: 2016-03-28T16:13:16-05:00 List-Id: wrote in message news:060566e9-c555-4eee-a40d-8ed338643d9e@googlegroups.com... >> Is there a reason why not to use (Natural range <>)? > >It seems like a simple question, but digging through my mind, I dug out >why. > >I have plans for this type, and all my plans involve indexes from 1 to n. >Someone >else may have different plans, but that is their choice. In my case >though, I expect >to do lots of arithmetic to arrive at the correct index. Is it possible >that some >intermediate will have a zero or negative value? Sure. Should an Ada >compiler try >to do that gotcha range check? No. But if at some point there is a >parameter or >function return that should not be range checked, this works. As I'm sure you know, all intermediate results in Ada are of the base type, and are never range checked. That only happens when the expression value is stored or otherwise consumed (i.e. used as an array index). And in the rare case that someone needs negative numbers, they can use 'Base. (i.e. Natural'Base). But I would complain about using either Natural or Integer. That puts the range of the array as implementation defined, and it sometimes ends up smaller than one might expect. I always suggest using a dedicated type for anything other than throwaway uses. I suppose that's not quite as critical in this case, but then again, large indexes are just as goofy as negative ones for this use (what card deck has 100_000 cards?). Randy.