comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: syntaxic exploration
Date: Sat, 23 Dec 2017 00:33:11 +0200
Date: 2017-12-23T00:33:11+02:00	[thread overview]
Message-ID: <fa5fh7FrcemU1@mid.individual.net> (raw)
In-Reply-To: <e3e60437-c49f-4908-a1cd-3b2f2e5b7ced@googlegroups.com>

On 17-12-22 22:25 , Mehdi Saada wrote:
> How about that, then:
> return RES: T_POLYNOME :=
> 	T_DEGRE'MAX(POLY_A.DEGRE,POLY_B.DEGRE),(0..POLY_A.COEF'Last => POLY_A.COEF, others => Nulle)) do
> It says "p_poly_v1_g.adb:63:51: dynamic or empty choice in aggregate must be the only choice"

(You have omitted the opening '(', after the ":=".)

Yes, the range 0..POLY_A.COEF'Last is dynamic, so the error message is 
valid.

Moreover, here, too, the expression after the index range should be a 
T_RATIONNEL, not an array like POLY_A.COEF. The semantics of an 
association A .. B => X, in an array aggregate, is to give the same 
value, X, to all elements in the index range A .. B, so it is _not_ what 
you want to do here.

> I would like to write this (POLY_A.COEF'Range => POLY_A.COEF, others => Nulle)

That is equivalent, and should give you the same error, and also be 
wrong in the same way.

> but I know "POLY_A.COEF'Range =>" must be followed by a value
> of T_RATIONNEL, not a slice.

The same is true for "0..POLY_A.COEF'Last =>".

> But I don't know how to write "PUT POLY_A.COEF there, and as much
> Nulle as needed to fill the void if by chance POLY_B.DEGRE > POLY_A.DEGRE"

If you insist on using an aggregate to initialise RES, you could use 
this form, with array concatenation ("&" operator) for the COEF component:

    return RES : T_POLYNOME :=
      (T_DEGRE'MAX (POLY_A.DEGRE, POLY_B.DEGRE),
         POLY_A.COEF
       & (1 .. Xxx'MAX (0, POLY_B.DEGRE - POLY_A.DEGRE) => Nulle));

where Xxx is the index type of the COEF array (I forget its name).

However, I would do it differently; I would declare RES with just its 
discriminant:

    return
       RES : T_POLYNOME (T_DEGRE'MAX (POLY_A.DEGRE, POLY_B.DEGRE))
    do
       -- Assign values to RES.COEF using loops, something like:

       for C in RES.COEF'Range loop
          RES.COEF(C) :=
              (if C in POLY_A.COEF'Range then POLY_A.COEF(C) else 0)
            + (if C in POLY_B.COEF'Range then POLY_B.COEF(C) else 0);
       end loop;
    end return;

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

  reply	other threads:[~2017-12-22 22:33 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-20 17:28 syntaxic exploration Mehdi Saada
2017-12-20 17:32 ` Mehdi Saada
2017-12-20 20:08   ` Niklas Holsti
2017-12-20 22:18     ` Mehdi Saada
2017-12-20 22:45       ` Mehdi Saada
2017-12-21  7:24         ` Randy Brukardt
2017-12-21  7:44           ` Niklas Holsti
2017-12-21  7:21   ` Randy Brukardt
2017-12-21 16:24     ` Jeffrey R. Carter
2017-12-22  5:01       ` Robert Eachus
2017-12-22 21:15         ` Simon Clubley
2017-12-22 22:11           ` Niklas Holsti
2017-12-22 22:51             ` Dmitry A. Kazakov
2017-12-23  7:15               ` Niklas Holsti
2017-12-23 16:23             ` Jeffrey R. Carter
2017-12-24  3:37               ` Robert Eachus
2017-12-24 13:39                 ` Niklas Holsti
2017-12-24 13:32               ` Niklas Holsti
2017-12-25 13:40                 ` Jeffrey R. Carter
2017-12-25 14:42                   ` Mehdi Saada
2017-12-25 17:03                     ` Dmitry A. Kazakov
2017-12-25 18:27                     ` Niklas Holsti
2017-12-25 20:12                     ` Jacob Sparre Andersen
2017-12-20 20:05 ` Niklas Holsti
2017-12-20 22:48 ` Mehdi Saada
2017-12-20 23:39   ` Mehdi Saada
2017-12-21  0:35 ` Mehdi Saada
2017-12-21  7:18 ` Randy Brukardt
2017-12-21 19:23   ` G. B.
2017-12-21 23:46   ` bj.mooremr
2017-12-22 23:45     ` Randy Brukardt
2017-12-22 13:31 ` Mehdi Saada
2017-12-22 18:00   ` Mehdi Saada
2017-12-22 18:27   ` Niklas Holsti
2017-12-22 20:25     ` Mehdi Saada
2017-12-22 22:33       ` Niklas Holsti [this message]
2017-12-23  1:47 ` Mehdi Saada
2017-12-23  7:17   ` Niklas Holsti
2017-12-23 11:23     ` Mehdi Saada
2017-12-23 11:39       ` Mehdi Saada
2017-12-23 12:09         ` Niklas Holsti
2017-12-23 12:12 ` Mehdi Saada
2017-12-23 12:16   ` Mehdi Saada
2017-12-23 13:04     ` Niklas Holsti
2017-12-23 14:02       ` Mehdi Saada
2017-12-23 14:46         ` Mehdi Saada
2017-12-23 15:03           ` Mehdi Saada
2017-12-23 22:11             ` Niklas Holsti
2017-12-24  0:55               ` Mehdi Saada
replies disabled

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