From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: syntaxic exploration Date: Sat, 23 Dec 2017 00:33:11 +0200 Organization: Tidorum Ltd Message-ID: References: <0d33e631-e63d-4346-ac95-5eec72127f4f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net jxtqnPiiFsy7GPJwBmWX2AAY3h9EJGsCRbKYs+soyuPQUSv/3a Cancel-Lock: sha1:NycekTaHBC7vGQuRpLsSafi4/L0= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: reader02.eternal-september.org comp.lang.ada:49596 Date: 2017-12-23T00:33:11+02:00 List-Id: 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 . @ .