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.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: syntaxic exploration Date: Wed, 20 Dec 2017 22:05: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 eihjvb2N0ie0e38OYAFqxwkClGixv4oEHVjDuXE7Og0dawqg0e Cancel-Lock: sha1:YZzaKcjWeJTG0Ln7hS1BXhLFwT8= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <0d33e631-e63d-4346-ac95-5eec72127f4f@googlegroups.com> Xref: reader02.eternal-september.org comp.lang.ada:49552 Date: 2017-12-20T22:05:11+02:00 List-Id: On 17-12-20 19:28 , Mehdi Saada wrote: > I'm being modelizing polynomes. It is difficult to help you if you don't show the type declarations! So my suggestions below are not sure to work. > I've got those two things: > p_poly_v1_g.adb:51:21: iterable name cannot be a discriminant-dependent component of a mutable object > Ah ? So I can't write that ? > return RESULTAT : T_POLYNOME := POLY do > for ELEMENT of RESULTAT.COEF loop > ELEMENT := - ELEMENT; > end loop; > end return; You are trying to iterate over RESULTAT.COEF, which seems to be an array with an index range that depends on RESULTAT.DEGRE. The error message tells you that this is not allowed, because RESULTAT is mutable (not constant) and therefore RESULTAT.DEGRE and thus the index range of RESULTAT.COEF could change during the iteration. The Annotated Ada Reference Manual gives the following rationale for this rule: "Reason: This is the same rule that applies to renames; it serves the same purpose of preventing the object from disappearing while the iterator is still using it." It should work if you change the loop to be an ordinary loop over RESULTAT.COEF'Range, with indexing of its elements. There will then be (at least in principle) run-time checks to ensure that the indexing is legal even if RESULTAT has changed. In practice these checks may be optimised away. > I've got that too: > p_poly_v1_g.adb:59:86: selector name should be identifier or "others" > > return RES: T_POLYNOME := > (T_DEGRE'MAX(POLY_A.DEGRE,POLY_B.DEGRE), > POLY_A.COEF'Range => POLY_A.COEF, others => Nulle) do Here you have omitted the '(' ')' around the nested array aggregate. It should be return RES: T_POLYNOME := (T_DEGRE'MAX(POLY_A.DEGRE,POLY_B.DEGRE), (POLY_A.COEF'Range => POLY_A.COEF, others => Nulle)) do > I thought X'Range was strictly equivalent to X'First..X'Last ? Of > course, poly is a mutable article, with two components, Degre > (derived from NATURAL), and COEF, array. Which is why the aggregate for COEF is nested and must have its own parentheses. > I have that too: > for IND in POLY_R.COEF'Range loop > POLY_R.COEF(IND) := POLY_R.COEF(IND)*(IND+1); > end loop; > > COEF's elements of T_RATIONNEL type, themselves record types. > IND is of type T_DEGRE, so why do I have that: > p_poly_v1_g.adb:73:43: expected type "Standard.Integer" > p_poly_v1_g.adb:73:43: found private type "T_Rationnel" Again hard to be sure, as you didn't show the actual type declarations, but what is your question, really? Is it (1) why the compiler gives you an error, or (2) why the first message says "Standard.Integer" instead of "T_DEGRE"? The answer to the first question is that you have not defined an "*" operator for these operand types, or this operator is not visible at this point in the code. The answer to the second question is probably that the index type of the COEF array is a subtype of Standard.Integer, not a type of its own. GNAT's error messages of this kind refer to the underlying type, not to the subtype, because the operator is identified from the type and not from the subtype. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .