From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: "unconstrained subtype in component declaration" vs "discriminant in constraint must appear alone" Date: Mon, 22 Feb 2021 07:32:16 +0100 Organization: Adalog Message-ID: References: <4086f350-c56b-4eec-91d3-ef685230b011n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 22 Feb 2021 06:32:15 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="e9beaac18cbb11fa3083b7c2ec09b13f"; logging-data="31004"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bC/+iSeYRaS20UPPHfiuS" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cancel-Lock: sha1:TmyDMWs0CPY15UgzvdgOyFqiB7c= In-Reply-To: <4086f350-c56b-4eec-91d3-ef685230b011n@googlegroups.com> Content-Language: fr Xref: reader02.eternal-september.org comp.lang.ada:61406 List-Id: Le 22/02/2021 à 01:14, Mehdi Saada a écrit : > this message "unconstrained subtype in component declaration" > arises from this: > > subtype Limit_number is Natural range 0..51; > type CARDS is new Natural range Limit_number'Range; > type Sets_of_Card is array (Limit_number range <>) of Cards; > function INITIALIZATION (Nb: Nombre_cartes) return Sets_of_Card; > type CARDS_SETS (Nb: Nombre_cartes) is record > Set: Sets_of_Card := INITIALIZATION (Nb); > end record; > > okay, > then this "Set: Sets_of_Card (0..nb-1) := INITIALIZATION (Nb);" > gives "discriminant in constraint must appear alone" ! > |[{|@]ŋ¤£# !! > > How do you do ? > 1) Forget about Integer, if you want an independent integer type, define it as such: type Cards is range 0..51; (BTW: why not 1..52?) 2) Components of arrays and records must have a definite size 3) Sets_of_Card (0..nb-1) I think you meant Sets_of_Card (nb-1). Yes, you cannot make computations in a discriminant constraint. Although this may seem sometimes frustrating to the user, it was required for implementation reasons. However, in your case, using the natural range of 1..52 would avoid the issue. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr