* Arrays in Ada 2012
@ 2017-06-06 11:47 Anatoly Chernyshev
2017-06-06 12:17 ` Dmitry A. Kazakov
` (2 more replies)
0 siblings, 3 replies; 23+ messages in thread
From: Anatoly Chernyshev @ 2017-06-06 11:47 UTC (permalink / raw)
Hello everyone,
Consider the following nice Ada 2012 construct:
--
procedure test is
type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of long_long_integer;
ab:a1;
cnt:long_long_integer:=0;
begin
for e of ab loop
cnt:=cnt+1;
e:=cnt;
end loop;
end test;
--
Is there a way (e.g. some attribute) to find the indices of the array for a current e within the cycle above?
Suppose, I want to calculate something with the indices, or have an exit condition.
Of course, I can always build a standard set of for loops, but I already get addicted to that new concept, so don't want to look back.
Thanks in advance.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 11:47 Arrays in Ada 2012 Anatoly Chernyshev
@ 2017-06-06 12:17 ` Dmitry A. Kazakov
2017-06-06 13:17 ` Simon Wright
2017-06-06 13:19 ` AdaMagica
2017-06-18 2:14 ` Arrays in Ada 2020 Ivan Levashev
2 siblings, 1 reply; 23+ messages in thread
From: Dmitry A. Kazakov @ 2017-06-06 12:17 UTC (permalink / raw)
On 06/06/2017 13:47, Anatoly Chernyshev wrote:
> Consider the following nice Ada 2012 construct:
>
> --
> procedure test is
> type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of long_long_integer;
> ab:a1;
> cnt:long_long_integer:=0;
> begin
> for e of ab loop
> cnt:=cnt+1;
> e:=cnt;
> end loop;
> end test;
> --
>
> Is there a way (e.g. some attribute) to find the indices of the
> array for a current e within the cycle above?
The greater dimension index changes first, so:
I6 := Count mod 35 + 1;
I5 := (Count / 35) mod 35 + 1;
I4 := (Count / 35**2) mod 35 + 1;
I3 := (Count / 35**3) mod 35 + 1;
I2 := (Count / 35**4) mod 35 + 1;
I1 := Count / 35**5 + 1;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 12:17 ` Dmitry A. Kazakov
@ 2017-06-06 13:17 ` Simon Wright
2017-06-06 13:57 ` Dmitry A. Kazakov
0 siblings, 1 reply; 23+ messages in thread
From: Simon Wright @ 2017-06-06 13:17 UTC (permalink / raw)
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> On 06/06/2017 13:47, Anatoly Chernyshev wrote:
>
>> Consider the following nice Ada 2012 construct:
>>
>> --
>> procedure test is
>> type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of long_long_integer;
>> ab:a1;
>> cnt:long_long_integer:=0;
>> begin
>> for e of ab loop
>> cnt:=cnt+1;
>> e:=cnt;
>> end loop;
>> end test;
>> --
>>
>> Is there a way (e.g. some attribute) to find the indices of the
>> array for a current e within the cycle above?
>
> The greater dimension index changes first, so:
I don't think this is right? it's the last index that changes first,
with Ada.Text_IO; use Ada.Text_IO;
procedure Arrays is
type A1 is array (0 .. 1, 41 .. 42) of Integer;
A : A1 := ((1, 2), (3, 4));
begin
for E of A loop
Put (E'Img);
end loop;
New_Line;
for J in A'Range (1) loop
for K in A'Range (2) loop
Put_Line (J'Img & K'Img & A (J, K)'Img);
end loop;
end loop;
end Arrays;
produces
$ ./arrays
1 2 3 4
0 41 1
0 42 2
1 41 3
1 42 4
> I6 := Count mod 35 + 1;
> I5 := (Count / 35) mod 35 + 1;
> I4 := (Count / 35**2) mod 35 + 1;
> I3 := (Count / 35**3) mod 35 + 1;
> I2 := (Count / 35**4) mod 35 + 1;
> I1 := Count / 35**5 + 1;
Should be able to use 'Length (N) in there!
ARM 3.6.2(10),
http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-6-2.html#p10
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 11:47 Arrays in Ada 2012 Anatoly Chernyshev
2017-06-06 12:17 ` Dmitry A. Kazakov
@ 2017-06-06 13:19 ` AdaMagica
2017-06-06 20:56 ` Randy Brukardt
2017-06-18 2:14 ` Arrays in Ada 2020 Ivan Levashev
2 siblings, 1 reply; 23+ messages in thread
From: AdaMagica @ 2017-06-06 13:19 UTC (permalink / raw)
Am Dienstag, 6. Juni 2017 13:47:06 UTC+2 schrieb Anatoly Chernyshev:
> Hello everyone,
>
> Consider the following nice Ada 2012 construct:
>
> --
> procedure test is
> type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of long_long_integer;
> ab:a1;
> cnt:long_long_integer:=0;
> begin
> for e of ab loop
> cnt:=cnt+1;
> e:=cnt;
> end loop;
> end test;
> --
>
> Is there a way (e.g. some attribute) to find the indices of the array for a current e within the cycle above?
No, there are no attributes giving the current indices. You have to use the nested loops form if you need the indices.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 13:17 ` Simon Wright
@ 2017-06-06 13:57 ` Dmitry A. Kazakov
2017-06-06 21:59 ` Simon Wright
0 siblings, 1 reply; 23+ messages in thread
From: Dmitry A. Kazakov @ 2017-06-06 13:57 UTC (permalink / raw)
On 06/06/2017 15:17, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> The greater dimension index changes first, so:
>
> I don't think this is right? it's the last index that changes first,
Isn't that same? Meaning: "first" = "more frequently".
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 13:19 ` AdaMagica
@ 2017-06-06 20:56 ` Randy Brukardt
2017-06-07 7:06 ` Dmitry A. Kazakov
0 siblings, 1 reply; 23+ messages in thread
From: Randy Brukardt @ 2017-06-06 20:56 UTC (permalink / raw)
"AdaMagica" <christ-usch.grein@t-online.de> wrote in message
news:e4066890-cc2c-496e-a6ce-f9a9ef9dc3f5@googlegroups.com...
> Am Dienstag, 6. Juni 2017 13:47:06 UTC+2 schrieb Anatoly Chernyshev:
>> Hello everyone,
>>
>> Consider the following nice Ada 2012 construct:
>>
>> --
>> procedure test is
>> type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of
>> long_long_integer;
>> ab:a1;
>> cnt:long_long_integer:=0;
>> begin
>> for e of ab loop
>> cnt:=cnt+1;
>> e:=cnt;
>> end loop;
>> end test;
>> --
>>
>> Is there a way (e.g. some attribute) to find the indices of the array
>> for a current e within the cycle above?
>
> No, there are no attributes giving the current indices. You have to use
> the nested loops form if you need the indices.
More than likely, the compiler generates code that doesn't even know the
indices in question, as doing address math is much cheaper than redoing an
address calculation on each loop. (This is an optimization called "strength
reduction" that some compilers can do with the conventional loop form, but
it's better to start out with the reduced code.)
That is, the loop will be generated as something like: [The following is
pseudo code that's not all legal Ada code, but I hope you get the idea...]
Current := AB(AB'First(1), ..., AB'First(6))'Address;
Finish := AB(AB'Last(1), ..., AB'Last(6))'Address;
while Current <= Finish loop
cnt:=cnt+1;
Current.all :=cnt;
Current := Current + Long_Long_Integer'Size/Storage_Unit;
end loop;
No indices anywhere, and having a way to provide them would prevent the
optimization (or would be very complicated in the general case).
Randy.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 13:57 ` Dmitry A. Kazakov
@ 2017-06-06 21:59 ` Simon Wright
0 siblings, 0 replies; 23+ messages in thread
From: Simon Wright @ 2017-06-06 21:59 UTC (permalink / raw)
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> On 06/06/2017 15:17, Simon Wright wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>>> The greater dimension index changes first, so:
>>
>> I don't think this is right? it's the last index that changes first,
>
> Isn't that same? Meaning: "first" = "more frequently".
I was confused by "the greater dimension". I think you must mean the
index with the greater N as in 'Length(N)? I suppose I was thinking that
the earlier (as read) dimensions would be "more important",
i.e. greater. Anyway, certainly the last index changes most rapidly.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-06 20:56 ` Randy Brukardt
@ 2017-06-07 7:06 ` Dmitry A. Kazakov
2017-06-07 11:47 ` Anatoly Chernyshev
2017-06-08 0:51 ` Randy Brukardt
0 siblings, 2 replies; 23+ messages in thread
From: Dmitry A. Kazakov @ 2017-06-07 7:06 UTC (permalink / raw)
On 06/06/2017 22:56, Randy Brukardt wrote:
> Current := Current + Long_Long_Integer'Size/Storage_Unit;
A bit OT question.
I always use rounding in the corresponding cases
(Long_Long_Integer'Size + Storage_Unit - 1) / Storage_Unit;
Is this an overkill from the point of view the permissions RM gives to
array implementation?
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-07 7:06 ` Dmitry A. Kazakov
@ 2017-06-07 11:47 ` Anatoly Chernyshev
2017-06-07 12:15 ` Dmitry A. Kazakov
2017-06-08 0:55 ` Randy Brukardt
2017-06-08 0:51 ` Randy Brukardt
1 sibling, 2 replies; 23+ messages in thread
From: Anatoly Chernyshev @ 2017-06-07 11:47 UTC (permalink / raw)
On Wednesday, June 7, 2017 at 7:06:13 PM UTC+12, Dmitry A. Kazakov wrote:
> On 06/06/2017 22:56, Randy Brukardt wrote:
>
> > Current := Current + Long_Long_Integer'Size/Storage_Unit;
>
> A bit OT question.
>
> I always use rounding in the corresponding cases
>
> (Long_Long_Integer'Size + Storage_Unit - 1) / Storage_Unit;
>
> Is this an overkill from the point of view the permissions RM gives to
> array implementation?
>
Miserable life of a computer scientist...
Couple of minor questions:
1 (to Dmitry): Aren't you screwing up the whole idea when using plain '1' in the formula above?
2 (to Randy): Would it be more convenient to declare a constant 'one' in the package, e.g.
ll1: constant long_long_integer:=Long_Long_Integer'Size/Storage_Unit;
and use it throughout when dealing with long_long_integers? So that, to stay on the bright side, every l_l_int operation would be brought into error-proof shape by multiplying by this constant: Current:=ll1*(current+1);
PS: Thanks to everyone answered, that's what I wanted to know.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-07 11:47 ` Anatoly Chernyshev
@ 2017-06-07 12:15 ` Dmitry A. Kazakov
2017-06-08 0:55 ` Randy Brukardt
1 sibling, 0 replies; 23+ messages in thread
From: Dmitry A. Kazakov @ 2017-06-07 12:15 UTC (permalink / raw)
On 07/06/2017 13:47, Anatoly Chernyshev wrote:
> On Wednesday, June 7, 2017 at 7:06:13 PM UTC+12, Dmitry A. Kazakov wrote:
>> On 06/06/2017 22:56, Randy Brukardt wrote:
>>
>>> Current := Current + Long_Long_Integer'Size/Storage_Unit;
>>
>> A bit OT question.
>>
>> I always use rounding in the corresponding cases
>>
>> (Long_Long_Integer'Size + Storage_Unit - 1) / Storage_Unit;
>>
>> Is this an overkill from the point of view the permissions RM gives to
>> array implementation?
>
> Miserable life of a computer scientist...
>
> Couple of minor questions:
>
> 1 (to Dmitry): Aren't you screwing up the whole idea when using plain '1' in the formula above?
It is no problem, integer literals are kind of overloaded. The
expression above is of universal integer type until it gets forced into
the target type, Storage_Offset in the case of address arithmetic.
BTW, if you don't like constant you could use this instead:
(Long_Long_Integer'Size + Storage_Offset'Pred (Storage_Unit)) /
Storage_Unit;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-07 7:06 ` Dmitry A. Kazakov
2017-06-07 11:47 ` Anatoly Chernyshev
@ 2017-06-08 0:51 ` Randy Brukardt
2017-06-08 7:07 ` Dmitry A. Kazakov
1 sibling, 1 reply; 23+ messages in thread
From: Randy Brukardt @ 2017-06-08 0:51 UTC (permalink / raw)
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:oh88l2$gsf$1@gioia.aioe.org...
> On 06/06/2017 22:56, Randy Brukardt wrote:
>
>> Current := Current + Long_Long_Integer'Size/Storage_Unit;
>
> A bit OT question.
>
> I always use rounding in the corresponding cases
>
> (Long_Long_Integer'Size + Storage_Unit - 1) / Storage_Unit;
>
> Is this an overkill from the point of view the permissions RM gives to
> array implementation?
The definition of 'Size is stupid, so you need rounding like that to be
portable. It's probably not necessary for base types, but if you had
(Natural'Size / Storage_Unit)
you would get the wrong answer (Ada requires Natural'Size to be one less
than Integer'Size, so it usually is 15 or 31 or 63).
Probably a better solution is to use 'Object_Size for such expressions, but
that is only portable to Ada 202x compilers (for which none exist yet for
obvious reasons). Object_Size usually will be a multiple of the storage
unit; that's the Implementation Advice for it, but of course some
implementation could ignore that in some circumstance.
Randy.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-07 11:47 ` Anatoly Chernyshev
2017-06-07 12:15 ` Dmitry A. Kazakov
@ 2017-06-08 0:55 ` Randy Brukardt
1 sibling, 0 replies; 23+ messages in thread
From: Randy Brukardt @ 2017-06-08 0:55 UTC (permalink / raw)
"Anatoly Chernyshev" <achernyshev@gmail.com> wrote in message
news:6f8707d3-a5a2-48f2-8c16-8eed3fa333f9@googlegroups.com...
...
> 2 (to Randy): Would it be more convenient to declare a constant 'one' in
> the package, e.g.
> ll1: constant long_long_integer:=Long_Long_Integer'Size/Storage_Unit;
> and use it throughout when dealing with long_long_integers? So that, to
> stay on the bright side,
> every l_l_int operation would be brought into error-proof shape by
> multiplying by this constant:
> Current:=ll1*(current+1);
A constant might make sense if you use it often enough, but PLEASE give it a
reasonable name. Something like "Component_Size" seems to make sense.
It wouldn't make sense in the pseudo-code, as that is what the compiler is
going to generate and the compiler is going to generate everything using
calculated values. (There's no named constants in machine code!)
Randy.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-08 0:51 ` Randy Brukardt
@ 2017-06-08 7:07 ` Dmitry A. Kazakov
2017-06-09 3:23 ` Randy Brukardt
0 siblings, 1 reply; 23+ messages in thread
From: Dmitry A. Kazakov @ 2017-06-08 7:07 UTC (permalink / raw)
On 08/06/2017 02:51, Randy Brukardt wrote:
> The definition of 'Size is stupid, so you need rounding like that to be
> portable.
You mean being bit size or being kind of weakly typed (universal
integer). I disagree on the first and agree on the second. It possibly
should be overloaded:
function 'Size (...) return Storage_Count; -- Storage units
function 'Size (...) return Storage_Size; -- Bits
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2012
2017-06-08 7:07 ` Dmitry A. Kazakov
@ 2017-06-09 3:23 ` Randy Brukardt
0 siblings, 0 replies; 23+ messages in thread
From: Randy Brukardt @ 2017-06-09 3:23 UTC (permalink / raw)
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:ohat3q$lon$1@gioia.aioe.org...
> On 08/06/2017 02:51, Randy Brukardt wrote:
>
>> The definition of 'Size is stupid, so you need rounding like that to be
>> portable.
>
> You mean being bit size or being kind of weakly typed (universal integer).
> I disagree on the first and agree on the second. It possibly should be
> overloaded:
>
> function 'Size (...) return Storage_Count; -- Storage units
> function 'Size (...) return Storage_Size; -- Bits
The definition of 'Size is stupid, because it's neither the bit size nor the
usual allocation size, but a weird hybrid of both. It's primary effect is to
provide a lower bound for packing, which is hardly ever what you want to
limit. (Why would you want to prevent someone from packing some component?)
And 'Size has no effect at all on what you can write in other rep. clauses,
like 'Component_Size and record representations. So setting 'Size almost
never does what you want (unless the compiler tries to be friendly -- but
that runs into problems with the required default value of Size).
Thus GNAT (and soon Ada) introduced 'Object_Size, which gives the UPPER
bound on the allocated size. A much more useful thing to bound - you can
ensure that type Byte really only uses a byte, for instance.
Randy.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-06 11:47 Arrays in Ada 2012 Anatoly Chernyshev
2017-06-06 12:17 ` Dmitry A. Kazakov
2017-06-06 13:19 ` AdaMagica
@ 2017-06-18 2:14 ` Ivan Levashev
2017-06-18 3:00 ` Nasser M. Abbasi
2 siblings, 1 reply; 23+ messages in thread
From: Ivan Levashev @ 2017-06-18 2:14 UTC (permalink / raw)
Hello!
FYI Ada 2020 is about to bring some improvements:
http://www.ada-auth.org/standards/2xrm/html/RM-4-3-3.html
> G : constant Matrix :=
> (for I in 1 .. 4 =>
> (for J in 1 .. 4 =>
> (if I = J then 1.0 else 0.0))); -- Identity matrix
Best Regards,
Ivan Levashev,
Barnaul
--
If you want to get to the top, you have to start at the bottom
http://forum.pascal.net.ru/
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-18 2:14 ` Arrays in Ada 2020 Ivan Levashev
@ 2017-06-18 3:00 ` Nasser M. Abbasi
2017-06-18 12:06 ` Robert Eachus
2017-06-18 20:15 ` Pascal Obry
0 siblings, 2 replies; 23+ messages in thread
From: Nasser M. Abbasi @ 2017-06-18 3:00 UTC (permalink / raw)
On 6/17/2017 9:14 PM, Ivan Levashev wrote:
> Hello!
>
> FYI Ada 2020 is about to bring some improvements:
>
> http://www.ada-auth.org/standards/2xrm/html/RM-4-3-3.html
>
>> G : constant Matrix :=
>> (for I in 1 .. 4 =>
>> (for J in 1 .. 4 =>
>> (if I = J then 1.0 else 0.0))); -- Identity matrix
>
> Best Regards,
> Ivan Levashev,
> Barnaul
That is nice. But still too much code for such common operation.
In Matlab the same can be done using just
eye(4) % Identity matrix
For other languages
https://rosettacode.org/wiki/Identity_matrix
--Nasser
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-18 3:00 ` Nasser M. Abbasi
@ 2017-06-18 12:06 ` Robert Eachus
2017-06-18 20:15 ` Simon Wright
2017-06-19 6:36 ` Ivan Levashev
2017-06-18 20:15 ` Pascal Obry
1 sibling, 2 replies; 23+ messages in thread
From: Robert Eachus @ 2017-06-18 12:06 UTC (permalink / raw)
On Saturday, June 17, 2017 at 11:00:15 PM UTC-4, Nasser M. Abbasi wrote:
> On 6/17/2017 9:14 PM, Ivan Levashev wrote:
> >
> > FYI Ada 2020 is about to bring some improvements:
> >
> > http://www.ada-auth.org/standards/2xrm/html/RM-4-3-3.html
> >
> >> G : constant Matrix :=
> >> (for I in 1 .. 4 =>
> >> (for J in 1 .. 4 =>
> >> (if I = J then 1.0 else 0.0))); -- Identity matrix
> >
> > Best Regards,
> > Ivan Levashev,
> > Barnaul
>
> That is nice. But still too much code for such common operation.
What about:
with Ada.Numerics.Generic_Real_Arrays;
procedure Main is
package My_Arrays is new Ada.Numerics.Generic_Real_Arrays(Long_Float);
use My_Arrays;
Identity_4: Real_Matrix := Unit_Matrix(4);
begin null; end Main;
On a different but related subject, the body of Unit_Matrix should look like:
function Unit_Matrix (Order : Positive;
First_1, First_2 : Integer := 1)
return Real_Matrix is
Result: Real_Matrix(First_1..First_1+Order,
First_2..First_2+Order) := (others =>
(others => 0.0));
begin
for I in First_1..First_1+Order loop
Result(I, I-First_1+First_2) := 1.0;
end loop;
return Result;
end Unit_Matrix;
On modern virtual memory machines, new space (as opposed to reused stack space) is cleared to zeros and the compiler knows it. If you are allocating a large chunk of memory (in theory on the stack), the compiler can grab new memory and put a pointer on the stack. If you are working with large matrices, you either expect this to happen or handle it yourself. Setting the diagonal values to 1.0 is an operation repeated Order times not Order squared times, so let the compiler do the zeros as fast as possible, then worry about the ones.
Oh, and the compiler should create Result in place, rather than copying back. The fact that the view of the object that Unit_Matrix is assigned to may be constant won't affect things, the view of Result inside Unix_Matrix is not constant.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-18 3:00 ` Nasser M. Abbasi
2017-06-18 12:06 ` Robert Eachus
@ 2017-06-18 20:15 ` Pascal Obry
1 sibling, 0 replies; 23+ messages in thread
From: Pascal Obry @ 2017-06-18 20:15 UTC (permalink / raw)
Le samedi 17 juin 2017 à 22:00 -0500, Nasser M. Abbasi a écrit :
> That is nice. But still too much code for such common operation.
> In Matlab the same can be done using just
>
> eye(4) % Identity matrix
That"s not Matlab that's a function. There is an equivalent routine in
Ada.
--
Pascal Obry / Magny Les Hameaux (78)
The best way to travel is by means of imagination
http://www.obry.net
gpg --keyserver keys.gnupg.net --recv-key F949BD3B
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-18 12:06 ` Robert Eachus
@ 2017-06-18 20:15 ` Simon Wright
2017-06-20 13:33 ` Robert Eachus
2017-06-19 6:36 ` Ivan Levashev
1 sibling, 1 reply; 23+ messages in thread
From: Simon Wright @ 2017-06-18 20:15 UTC (permalink / raw)
Robert Eachus <rieachus@comcast.net> writes:
> function Unit_Matrix (Order : Positive;
> First_1, First_2 : Integer := 1)
> return Real_Matrix is
> Result: Real_Matrix(First_1..First_1+Order,
> First_2..First_2+Order) := (others =>
> (others => 0.0));
> begin
> for I in First_1..First_1+Order loop
> Result(I, I-First_1+First_2) := 1.0;
> end loop;
> return Result;
> end Unit_Matrix;
Isn't that 1 larger in each dimension than it should be?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-18 12:06 ` Robert Eachus
2017-06-18 20:15 ` Simon Wright
@ 2017-06-19 6:36 ` Ivan Levashev
2017-06-19 12:06 ` AdaMagica
1 sibling, 1 reply; 23+ messages in thread
From: Ivan Levashev @ 2017-06-19 6:36 UTC (permalink / raw)
18.06.2017 19:06, Robert Eachus пишет:
> Oh, and the compiler should create Result in place, rather than
> copying back.
There is extended return statement since Ada 2005.
Best Regards,
Ivan Levashev,
Barnaul
--
If you want to get to the top, you have to start at the bottom
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-19 6:36 ` Ivan Levashev
@ 2017-06-19 12:06 ` AdaMagica
2017-06-23 1:17 ` Randy Brukardt
0 siblings, 1 reply; 23+ messages in thread
From: AdaMagica @ 2017-06-19 12:06 UTC (permalink / raw)
Am Montag, 19. Juni 2017 08:39:24 UTC+2 schrieb Ivan Levashev:
> 18.06.2017 19:06, Robert Eachus пишет:
> > Oh, and the compiler should create Result in place, rather than
> > copying back.
>
> There is extended return statement since Ada 2005.
That's a common misunderstanding. The extended return statement does not force build-in-place. Only when you return a limited result, it will build in place.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-18 20:15 ` Simon Wright
@ 2017-06-20 13:33 ` Robert Eachus
0 siblings, 0 replies; 23+ messages in thread
From: Robert Eachus @ 2017-06-20 13:33 UTC (permalink / raw)
On Sunday, June 18, 2017 at 4:15:58 PM UTC-4, Simon Wright wrote:
> Robert Eachus <rieachus@comcast.net> writes:
>
> > function Unit_Matrix (Order : Positive;
> > First_1, First_2 : Integer := 1)
> > return Real_Matrix is
> > Result: Real_Matrix(First_1..First_1+Order,
> > First_2..First_2+Order) := (others =>
> > (others => 0.0));
> > begin
> > for I in First_1..First_1+Order loop
> > Result(I, I-First_1+First_2) := 1.0;
> > end loop;
> > return Result;
> > end Unit_Matrix;
>
> Isn't that 1 larger in each dimension than it should be?
Oops! Yes.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Arrays in Ada 2020
2017-06-19 12:06 ` AdaMagica
@ 2017-06-23 1:17 ` Randy Brukardt
0 siblings, 0 replies; 23+ messages in thread
From: Randy Brukardt @ 2017-06-23 1:17 UTC (permalink / raw)
"AdaMagica" <christ-usch.grein@t-online.de> wrote in message
news:aab7d06f-f4d4-4c08-b718-78f4e144f407@googlegroups.com...
Am Montag, 19. Juni 2017 08:39:24 UTC+2 schrieb Ivan Levashev:
> 18.06.2017 19:06, Robert Eachus ?????:
>> > Oh, and the compiler should create Result in place, rather than
>> > copying back.
>>
>> There is extended return statement since Ada 2005.
>
>That's a common misunderstanding. The extended return statement does not
>force build-in-place.
>Only when you return a limited result, it will build in place.
Right. But Ada compilers are allowed to build-in-place most function
results, and I'd guess that most do take advantage of that (it can matter a
lot to performance). (Not yet Janus/Ada, unfortunately, doing that is near
the top of the development list - but there are approximately 100 items near
the top of that list. :-)
Randy.
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2017-06-23 1:17 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-06 11:47 Arrays in Ada 2012 Anatoly Chernyshev
2017-06-06 12:17 ` Dmitry A. Kazakov
2017-06-06 13:17 ` Simon Wright
2017-06-06 13:57 ` Dmitry A. Kazakov
2017-06-06 21:59 ` Simon Wright
2017-06-06 13:19 ` AdaMagica
2017-06-06 20:56 ` Randy Brukardt
2017-06-07 7:06 ` Dmitry A. Kazakov
2017-06-07 11:47 ` Anatoly Chernyshev
2017-06-07 12:15 ` Dmitry A. Kazakov
2017-06-08 0:55 ` Randy Brukardt
2017-06-08 0:51 ` Randy Brukardt
2017-06-08 7:07 ` Dmitry A. Kazakov
2017-06-09 3:23 ` Randy Brukardt
2017-06-18 2:14 ` Arrays in Ada 2020 Ivan Levashev
2017-06-18 3:00 ` Nasser M. Abbasi
2017-06-18 12:06 ` Robert Eachus
2017-06-18 20:15 ` Simon Wright
2017-06-20 13:33 ` Robert Eachus
2017-06-19 6:36 ` Ivan Levashev
2017-06-19 12:06 ` AdaMagica
2017-06-23 1:17 ` Randy Brukardt
2017-06-18 20:15 ` Pascal Obry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox