From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.5 required=3.0 tests=BAYES_05,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: Discriminants or Constructor Function for Limited Types Date: Wed, 4 May 2022 11:40:10 +0200 Organization: A noiseless patient Spider Message-ID: References: <0b4ddd38-1f19-44fe-acd9-43a316ec9d29n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 4 May 2022 09:40:11 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="233f1155dc777537cd3ff84b743a010d"; logging-data="20019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N14ablB8r3hQWFnS/lbaja7cyKaVcC/4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Cancel-Lock: sha1:el0+hAF6hLcQMAQ9RwGdAzOd59Q= In-Reply-To: <0b4ddd38-1f19-44fe-acd9-43a316ec9d29n@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63809 List-Id: On 2022-05-04 11:02, R R wrote: > There are two ways (to my knowledge) how to initialize objects of limited types. Either the limited type has some discriminants > > type DLT (Width, Length : Positive) is tagged limited private; > Obj : DLT (3, 5); > > or I can provide a constructor function that takes corresponding parameters > > type LT (<>) is tagged limited private; > function Make (Width, Length : Positive) return LT; > Obj : LT := Make (3, 5); > > Do you recommend one way over the other? Why? Is it possible to combine both methods (discriminants plus constructor)? Just as you can do S : String := "Hello"; you can do Obj : DLT := New_DLT (3, 5); -- Jeff Carter "It has been my great privilege, many years ago, whilst traveling through the mountains of Paraguay, to find the Yack'Wee Indians drinking the juice of the cacti." The Old Fashioned Way 152