|
From: Dmitry A. Kazakov on 1 Sep 2005 14:34 On Thu, 01 Sep 2005 17:36:26 +0200, Georg Bauhaus wrote: > Dmitry A. Kazakov wrote: > >> -------------- >> The problem with the current (Ada 83) design is that it tries to abstract >> away trivial mathematical facts: > > As does a computer :-) It does what you tell it. Computers do not have free will! (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Gene on 1 Sep 2005 17:42 Ok. Thanks. And Jean-Pierre too. I completely agree with the marginal utility of other-than-1 least array indices. Still it makes complete sense for your code X: String(-99 .. -10_000); -- empty string Y: constant String := X & "Hello world." to generate an exception because the dest index range starts at -99. I have a much bigger problem with A : Int_Array(1..i - 1); B: Int_Array(i+1..10); .... .... := A & B; producing an array indexed from 1 when i = 2 and from 2 when i = 1. This still makes my head hurt. The starting point of a range of length zero is a perfectly logical concept. It's easy to draw such a range on a number line, for example. The fact that A'First is always defined is a tacit verification! So I'm still interested in an example that shows why the defined behavior makes sense. Gene
From: tmoran on 1 Sep 2005 18:56 >I completely agree with the marginal utility of other-than-1 least >array indices. I strongly disagree. While not dirt common, other 'firsts in declarations do occur. -n .. +n comes to mind. If you are going to handle slices, you have to assume 'first /= 1 anyway, so you're not losing much by allowing it in declarations. Using 'first instead of 1 also makes it simple to change between integer and enumeration value indexes. The way Ada.Text_IO.Get_Line (et al) returns Last, which works even if you passed it a slice, has surely prevented many an error as compared to other languages which would likely return a count (since "all arrays start at x") and depend on the programmer to do any arithmetic needed to turn it into an index. And if you started all arrays at 1, you probably wouldn't allow the idiom subtype cards is string(1 .. 80); subtype sequence is range 73 .. 80; ... if card(sequence) = (sequence=>' ') then
From: Georg Bauhaus on 2 Sep 2005 06:42 Dmitry A. Kazakov wrote: > On 01 Sep 2005 12:04:17 -0400, Robert A Duff wrote: >>Heh? You want this: >> >> procedure Put(S: String) is >> begin >> for I in S'First..S'Last loop -- equivalent to S'Range >> Put_Char(S(I)); >> >>to crash when S = ""? > > > Yes. What is your approach to subranges then? function h(s: String) return Unsigned_32 is prefix: String renames s(s'first .. s'first + Integer'min(3, s'length - 1)); result: Unsigned_32 := 0; begin for k in prefix'range loop result := result or Shift_Left(Character'pos(prefix(k)), (k - prefix'first) * 8); end loop; return result; end h; (If you could assume for the moment that there is no Unchecked_Conversion and not a different/better algorithm etc.) Georg
From: Georg Bauhaus on 2 Sep 2005 06:43
Dmitry A. Kazakov wrote: >>>The problem with the current (Ada 83) design is that it tries to abstract >>>away trivial mathematical facts: >> >>As does a computer :-) > > It does what you tell it. Computers do not have free will! (:-)) So why do you want to tell it about non-computer mathematics? |