comp.lang.ada
 help / color / mirror / Atom feed
* basic question on adding 2 arrays
@ 2014-07-13  3:34 Nasser M. Abbasi
  2014-07-13  4:09 ` Nasser M. Abbasi
  0 siblings, 1 reply; 7+ messages in thread
From: Nasser M. Abbasi @ 2014-07-13  3:34 UTC (permalink / raw)


I am really rusty in Ada since I have not used it for sometime.

Is there an easy way to add one slice of an array to another
without having to make an explicit loop?  Here is MWE

------------------------------------------------
with Ada.Text_IO;                       use Ada.Text_IO;

procedure foo is
    nPoints : constant Integer := 100;
    type grid_type is array (1 .. nPoints) of Float;
    now : grid_type := (others => 0.0);
    next: grid_type := now;
    begin
      next(2..now'length-1) := 1/2*
        (now(1..now'length-1)+now(3..now'length));
end foo;
--------------------------------------------------

I am basically trying to update an array (this is a finite difference
scheme).  The error is that "+" is not defined for the grid_type,
which I understand ofcourse. But wanted to ask if there is a way
to do this in-line without having to define a method for this.

For example, in Matlab or Fortran something like this works:

    next(2:end-1) = 1/2*(now(1:end-2)+now(3:end));

It is not big deal to defined "+" for the grid_type, but
wanted to check if there might be a way to do it without,
or a better way to do update.

thanks,
--Nasser

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-13 21:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-13  3:34 basic question on adding 2 arrays Nasser M. Abbasi
2014-07-13  4:09 ` Nasser M. Abbasi
2014-07-13  4:35   ` Nasser M. Abbasi
2014-07-13  6:33   ` Jeffrey Carter
2014-07-13 10:10     ` AdaMagica
2014-07-13 16:25       ` Jacob Sparre Andersen
2014-07-13 21:53       ` Jeffrey Carter

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