comp.lang.ada
 help / color / mirror / Atom feed
From: stefan-lucks@see-the.signature
Subject: Re: Array Help?
Date: Wed, 29 Feb 2012 20:45:07 +0100
Date: 2012-02-29T20:45:07+01:00	[thread overview]
Message-ID: <Pine.LNX.4.64.1202292025510.3727@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <wcclinl7b1x.fsf@shell01.TheWorld.com>

On Wed, 29 Feb 2012, Robert A Duff wrote:

> Anyway, slices aren't really all that useful -- for many array types,
> you don't need them at all.  And slices as l-values, as in your
> example, are quite rare, because you really want to be able to
> change the length of the slice, if you want to change it at all.

Not quite. I quite frequently use something like

  X := X(X'Last) & (X'First .. X'Last-1) 

and 

  First := X'First; 
  while First < X'Last and then X(First) = ' ' loop 
    First := First + 1;
  end loop; 
  return X(First .. X'Last);

and similar constructs, where array slicing is a highly useful language 
feature. 

On the other hand, I agree that the fact that array slices carry their 
original indices with them is a misfeature of Ada. 

I would appreciate way to convert ingoing parameters into some standard 
indexing. For example (inventing a new syntax variant on the fly):

  procedure Sort(Items: in out array(generic Positive range <>) of T) is
    -- inside Sort, Items'First=1 and Item'Last = Items'Length
    -- regardless of the index type of the actual parameter
  begin
     ...
  end Sort;

and later call the same Sort procedure

  Sort(X);
  Sort(Y);
  Sort(Z);

for any one-dimensional array of type T, e.g.,  

  X: array (Positive range 3 .. 13) of T;
  Y: array (range 31 .. 3343) of T;
  type Month_Names is (January, [...] December);
  Z: array (Month_Names) of T;



-- 
---- Stefan.Lucks (at) uni-weimar.de, University of Weimar, Germany  ----
    <http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




  reply	other threads:[~2012-02-29 19:39 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 20:15 Array Help? Will
2012-02-28 20:47 ` Ludovic Brenta
2012-02-28 22:11   ` Simon Wright
2012-02-28 23:09     ` Will
2012-02-29  0:24   ` Adam Beneschan
2012-02-28 20:50 ` Gautier write-only
2012-02-28 21:33 ` Simon Wright
2012-02-29  0:27   ` Adam Beneschan
2012-02-29  8:00     ` Simon Wright
2012-02-29  8:48       ` Simon Wright
2012-02-29  0:22 ` Adam Beneschan
2012-02-29 16:09   ` Robert A Duff
2012-02-29 16:50     ` Ludovic Brenta
2012-02-29 18:24       ` Robert A Duff
2012-02-29 19:45         ` stefan-lucks [this message]
2012-02-29 20:45           ` Jeffrey Carter
2012-02-29 21:27             ` stefan-lucks
2012-02-29 23:06           ` Robert A Duff
2012-03-02 13:45             ` stefan-lucks
2012-03-07 23:58             ` Randy Brukardt
2012-03-08 11:20               ` stefan-lucks
2012-03-09  2:02                 ` Randy Brukardt
2012-03-09  8:48                   ` stefan-lucks
2012-03-09 21:10                     ` Randy Brukardt
2012-03-15  2:55                     ` BrianG
2012-03-15  7:46                       ` stefan-lucks
2012-02-29 20:07         ` Dmitry A. Kazakov
2012-02-29 23:15           ` Robert A Duff
2012-03-01  8:54             ` Dmitry A. Kazakov
2012-03-01 14:06               ` Robert A Duff
2012-02-29 20:47         ` Simon Wright
2012-02-29 22:23           ` Robert A Duff
2012-02-29 23:27             ` Robert A Duff
2012-03-01  0:53               ` Adam Beneschan
2012-03-01  7:16               ` Ludovic Brenta
2012-03-01 14:03                 ` Robert A Duff
2012-03-08  0:11                   ` Randy Brukardt
2012-03-08  0:08               ` Randy Brukardt
2012-02-29 23:30             ` Simon Wright
2012-02-29 18:35     ` Jeffrey Carter
2012-02-29 22:59       ` Robert A Duff
2012-02-29 23:51         ` Jeffrey Carter
2012-03-01  3:03           ` Robert A Duff
2012-02-29 20:40     ` Adam Beneschan
replies disabled

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