comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Playing cards.
Date: Mon, 28 Mar 2016 16:13:16 -0500
Date: 2016-03-28T16:13:16-05:00	[thread overview]
Message-ID: <ndc6pc$oia$1@loke.gir.dk> (raw)
In-Reply-To: 060566e9-c555-4eee-a40d-8ed338643d9e@googlegroups.com

<rieachus@comcast.net> 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.


  reply	other threads:[~2016-03-28 21:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-26 18:50 Playing cards rieachus
2016-03-26 20:46 ` Nasser M. Abbasi
2016-03-26 21:51 ` rieachus
2016-03-28 21:13   ` Randy Brukardt [this message]
2016-03-29  0:08     ` Dennis Lee Bieber
2016-03-29  3:29 ` rieachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox