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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,db88d0444fafe8eb,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g47g2000cwa.googlegroups.com!not-for-mail From: "Gene" Newsgroups: comp.lang.ada Subject: Surprise in array concatenation Date: 31 Aug 2005 20:16:43 -0700 Organization: http://groups.google.com Message-ID: <1125544603.561847.32140@g47g2000cwa.googlegroups.com> NNTP-Posting-Host: 216.190.181.85 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1125544608 4072 127.0.0.1 (1 Sep 2005 03:16:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 1 Sep 2005 03:16:48 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g47g2000cwa.googlegroups.com; posting-host=216.190.181.85; posting-account=ZFTPUQ0AAABW8AYEou9RtrBd-zTxz0_y Xref: g2news1.google.com comp.lang.ada:4351 Date: 2005-08-31T20:16:43-07:00 List-Id: Seldom am I surprised by Ada semantics, but today they got me. type Int_List_Type is array(Integer range <>) of Integer; procedure Main is function F(a : Int_List_Type) return Integer is i : Integer; begin if a'Length <= 1 then return a(1); else -- calculate i s.t. 1 <= i <= a'Last -- with some algorithm; details irrelevant ... return F(a(1..i - 1) & a(i + 1, a'Last)); end if; end Calculate; a : Int_List(1..100); begin -- yada yada; fill a with values Put(Calculate(F(a))); end; The gotcha is that when (and only when) i is determined to be zero, the concatenation in the recursive call to F produces a starting index of 2 rather than 1. Of course this causes the base case test to raise an exception in the next recursive call. This is in accordance with the ALRM and GNAT implements it perfectly. Yes I know how to recode this to use a'First instead of 1 as needed. Nonetheless the rule seems silly: When a leading zero-length array is catenated to another array the result takes on the starting index of the _second_ operand. This doesn't make sense to me. Why not use the starting index of the zero-length array? Gene