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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1fa85f3df5841ae1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors - querying multiple elements Date: 03 May 2005 19:30:29 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> <0uYbe.542$BE3.229@newsread2.news.pas.earthlink.net> <1wjh6qsazg3rg$.lupowyuqu0tw$.dlg@40tude.net> <1O2dnYJF_uSxAejfRVn-2Q@megapath.net> <14ts2mrny7fci.emc3y6pqq7za$.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1115163029 6437 192.74.137.71 (3 May 2005 23:30:29 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 3 May 2005 23:30:29 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:10901 Date: 2005-05-03T19:30:29-04:00 List-Id: "Dmitry A. Kazakov" writes: > On 02 May 2005 14:57:15 -0400, Robert A Duff wrote: > > > "Dmitry A. Kazakov" writes: > > > >> So "" is not allowed for any string type which index is not a > >> subtype/derived type S of some base type T, such that S'First>T'First. With > >> a nice consequence that: > >> > >> type T1 is range -2147483647..0; > > ^^^^^^^^^^ > > You misspelled "-2**31". ;-) > > Actually it is 1 - 2**31 (:-)), Right. Which proves my point, which is that your point would be clearer if you used "2**31" or whatever instead of putting in a literal. Without underscores, even! >... but the point is that it can be any number! Right. > The standard is silent about powers of 2. As well it should be, IMHO. >... Can I write a compiler with a > built-in integer type Short_Int which range is -5..5? Is this illegal? Yes. But the built-in types are irrelevant. What's relevant is the "base range" of a type. The RM says it has to be (almost) symmetric about zero. So, yes, if you say "type T is range 2..3" the base range could be -5..5 (according to the RM). > >> type T1_Array is array (T range <>) of Character; > >> > >> type T2 is range -2147483648..0; > >> type T2_Array is array (T range <>) of Character; > >> > >> type T3 is range -2147483649..0; > >> type T3_Array is array (T range <>) of Character; > >> > >> X : T1_Array := ""; -- Legal > >> Y : T2_Array := ""; -- Illegal > >> Z : T3_Array := ""; -- Again legal!!!!! > > > > Well, Ada's integer types are intended to be hardware-oriented, for > > better or worse. This empty-array issue is an extremely rare case. > > Consider: > > > > X1: T1 := T1'First; > > X2: T2 := T2'First; > > X3: T3 := T3'First; > > > > X1 := (X1-1)/2; > > X2 := (X2-1)/2; > > X3 := (X3-1)/2; > > > > Which of the above will raise Constraint_Error (due to overflow on the > > subtraction)? Well it's entirely implementation defined, but given > > typical hardware and compiler, you'll get the same behavior as with the > > empty strings. > > How would you formally, in the sense ARM 1.1.5, classify the error above > and one of using empty strings? It seems to me that to rely on > Constraint_Error above would be a bounded error. But programs using empty > strings would be illegal Ada programs. There's no "bounded error" here. These things raise C_E, or return the correct result. If every intermediate result is in the base range, the RM requires correct results; otherwise, it allows C_E or correct results. RM-4.9(34..35) might make some such things illegal -- I'm not sure. (Illegal = compile-time error.) > > Seems to me that arithmetic is a more common case. I mean, nobody makes > > arrays starting near -2**31. > > I don't think that statistical approach is appropriate here. Anyway it > makes an implementation of many generic algorithms and container libraries > very difficult if possible. I don't see a big problem here. If you're counting things, use signed integers, and start counting at zero or one. If you're using enums or modulars, you're not "counting", and zero-length arrays/vectors/whatever make no sense. > > I admit this stuff is a little bit error prone. That's what you get > > when the language is hardware oriented (for efficiency, of course). > > Is this the only way to achieve efficiency? No. I think I can design an efficent language that doesn't have these problems. But it ain't Ada. - Bob