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,1540032852ee6d61 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news1.google.com!news.germany.com!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Why does this work? (overloads) From: Georg Bauhaus In-Reply-To: <1170931228.165961.8170@m58g2000cwm.googlegroups.com> References: <1170823163.681564.186260@s48g2000cws.googlegroups.com> <1170881623.149455.139410@j27g2000cwj.googlegroups.com> <1170931228.165961.8170@m58g2000cwm.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-Id: <1170934493.5363.63.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Date: Thu, 08 Feb 2007 12:34:54 +0100 NNTP-Posting-Date: 08 Feb 2007 12:34:40 CET NNTP-Posting-Host: b3fa1c2c.newsspool2.arcor-online.net X-Trace: DXC=bGIo\?4VRI>T2Rfi6\BH3Y2[ZB5jhH]H<;A:ho7QcPOV3n7e6Eb1TJK1TQ4:gD@U`M5 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:9134 Date: 2007-02-08T12:34:40+01:00 List-Id: On Thu, 2007-02-08 at 02:40 -0800, Jerry wrote: > Jeffrey R. Carter wrote: > > Jerry wrote: > > > > > Yes, but time series are usually indexed from 0. Sometimes, the FFT > > > of a time series is indexed from 0 and sometimes -NN/2 .. NN/2-1. When > > > one uses a time series in a vector or matrix, conundrums obviously > > > arise, not only in computer code but in print. I once figured out how > > > to make Pascal let me have it both ways by declaring both types, one > > > type indexed 0..NN-1 and the other 1..NN, and then I set a pointer of > > > one type to an array originally declared with another type. I'm > > > guessing that Ada doesn't allow this, however. > > > > No pointers needed: > > > > A : Vector (0 .. N - 1); > > B : Vector (1 .. A'Length); > > > > A := B; > > B := A; > > > > This is called sliding. > > > Good point. However, it uses twice the memory, and worse, changes made > in A are not reflected in B without repeating the assignment A := B > (correct?) and vice versa. My Pascal trick had neither of these > problems yet carried boundary checking using either name. Not sure whether it is what you are after, but you could either use pointers to a common unconstrained array type, or simply slice renaming if possible: with Ada.Text_IO; use Ada; procedure sp is type Index is range 0 .. 666; type A is array (Index range <>) of Float; c: A(0 .. 3); x: A renames c(0 .. 2); y: A renames c(1 .. 3); function "*"(v, w: A) return Float; -- sum of products of pairwise matching components of `v` and `w` -- pre: v'length = w'length function "*"(v, w: A) return Float is result: Float := 0.0; j: Index := w'first; begin pragma assert(v'length = w'length); for k in v'range loop result := result + v(k) * w(j); j := j + 1; end loop; return result; end "*"; package FIO is new Text_IO.Float_IO(Float); begin FIO.Default_Aft := 2; FIO.Default_Exp := 0; c := (1.0, 3.2, 3.7, 2.4); FIO.Put(x * y); Text_IO.new_line; c(2) := 1.0; FIO.Put(x * y); Text_IO.new_line; x(2) := -1.3; FIO.Put(x * y); Text_IO.new_line; y(2) := +1.3; FIO.Put(x * y); Text_IO.new_line; end sp;