From: Peter C. Chapin on
Niklas Holsti wrote:

> Another solution -- which perhaps you have considered -- is to use a
> generic package to define row and matrix types:
>
> generic Size : Positive;
> package Matrices
> is
> type Row is array (1 .. Size) of Float;
> type Matrix is array (1 .. Size) of Row;
> end Matrices;
>
> However, this will probably force some other parts of your code to
> become generic, too, parametrized either by a Size, or by an instance of
> Matrices.
>

Actually I hadn't considered this, but such an approach might work well for
me. I'll have to consider it more.

Thanks!

Peter

From: Randy Brukardt on
I presume this was because the elements in question are not necessarily
adjacent. As such the code ends up being exactly the same (or sometimes
worse) than an explicitly coded loop.

And honestly, I don't see any real advantage to slices in terms of safety
(given that indexes are checked for in-range, as they are in Ada). I make
just as many mistakes with slices as I do with loops -- I find it hard to
figure out the ends of the two slices for assignment (which have to be the
same length - mine only are about 1/2 of the time); it's about the same
difficulty as figuring out the offset amount when writing a loop to copy
items. So I see it as a wash, other than that a one-dimensional slice can
generate much better code (using a direct memory-memory move the for entire
amount). The safety win comes for whole object assignments, not parts.

Randy.

"Jerry" <lanceboyle(a)qwest.net> wrote in message
news:ed36036c-8318-4f27-aaae-5329a8bfc83d(a)t31g2000prh.googlegroups.com...
> I've never understood why Ada does not allow slicing in
> multidimensional arrays. What are the safety issues involved? And how
> is it safe to force the programmer into ad hoc methods?
>
> Jerry


From: Randy Brukardt on
"Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> wrote in message
news:178rg3rch8qdu$.13cgkywb09x3p.dlg(a)40tude.net...
> On Sun, 31 Jan 2010 21:11:12 -0500, Peter C. Chapin wrote:
>
>> So I thought, "Perhaps A needs to be an array of arrays."
>>
>> type Matrix is array(Positive range <>) of WHAT_EXACTLY?
>>
>> Apparently the component type of an array needs to be fully constrained
>> (which
>> again makes sense)
>
> Not really. Arrays should have been allowed to have discriminants. That
> was
> missed in the language design.

Early Ada 9x had discriminants for arrays. The capability got dropped when
lots of "nice-to-have" features got dropped from Ada 95. Such "array" types
have to be implemented as discriminant dependent records anyway; there is no
real hope of performance improvement from them, but a lot of implementation
complication. (I recall I was one of the stronger opponents of this feature,
mostly for implementation cost/benefit reasons.)

So it is completely wrong to say that "this was missed in the language
design". The correct statement is that "this was explicitly rejected in the
language design".

Randy.


From: Jean-Pierre Rosen on
Jerry a �crit :
> I've never understood why Ada does not allow slicing in
> multidimensional arrays. What are the safety issues involved? And how
> is it safe to force the programmer into ad hoc methods?
>
One-dimensional slices are simple and efficient. Multidimensional slices
are a can of worms.

I guess you are thinking about rectangular slices. But why stop there? A
slice comprising the main diagonal and the diagonal above and below can
be very useful for some calculations. Or a slice which is the triangular
part of the upper half...

AFAICT, Fortran-99 does provide this - and the syntax is so complicated
that nobody uses it. And implementation is also a nightmare.

When designing a programming language, you have to stop at some point.
The ratio (cost of implementation) / usefulness is a good measure for
this. I think the ratio was simply to high for this feature.

--
---------------------------------------------------------
J-P. Rosen (rosen(a)adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
From: Jerry on
On Feb 2, 1:52 am, Jean-Pierre Rosen <ro...(a)adalog.fr> wrote:
> Jerry a écrit :> I've never understood why Ada does not allow slicing in
> > multidimensional arrays. What are the safety issues involved? And how
> > is it safe to force the programmer into ad hoc methods?
>
> One-dimensional slices are simple and efficient. Multidimensional slices
> are a can of worms.
>
> I guess you are thinking about rectangular slices. But why stop there? A
> slice comprising the main diagonal and the diagonal above and below can
> be very useful for some calculations. Or a slice which is the triangular
> part of the upper half...
>
> AFAICT, Fortran-99 does provide this - and the syntax is so complicated
> that nobody uses it. And implementation is also a nightmare.
>
> When designing a programming language, you have to stop at some point.
> The ratio (cost of implementation) / usefulness is a good measure for
> this. I think the ratio was simply to high for this feature.
>
> --
> ---------------------------------------------------------
>            J-P. Rosen (ro...(a)adalog.fr)
> Visit Adalog's web site athttp://www.adalog.fr

Well, yes, I was thinking of rectangular slices. No doubt the (cost of
implementation) / usefulness is high (and usage difficult) for non-
rectangular parts, but that is far less common than rectangular parts.
Python, Matlab/Octave, Igor Pro... all pull it off without too much
hassle (although Python asks you to imagine addressing the array by
the "cracks" between elements, as I recall--probably a disease of C-
style counting).

Jerry