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!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: What is an indefinite type and is there an example of it? Date: Wed, 7 Sep 2016 19:39:45 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <09169c05-5c31-40a6-8523-89aab3bca72e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 8 Sep 2016 02:39:52 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="d7c030f56102b58a2c16dea977db88bb"; logging-data="29242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189uRft+hCJSxTF5O+CWQXKs9ejTjE7LC4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <09169c05-5c31-40a6-8523-89aab3bca72e@googlegroups.com> Cancel-Lock: sha1:PeFixQmf9IX55s7/HuBVcVxmo2Y= Xref: news.eternal-september.org comp.lang.ada:31726 Date: 2016-09-07T19:39:45-07:00 List-Id: On 09/07/2016 06:20 PM, Andrew Shvets wrote: > > I'm trying to figure out what an indefinite type is. Ada Distilled doesn't > even have the string "indefinite" in the entire document. The Ada wikibook > seems to say that it's a type of that does not have its range defined... ok, > so does that make it an array that doesn't have it range defined at > compile-time? Is there more to this that I'm missing? "Indefinite subtype" is defined in ARM 3.3 (23/3): "A subtype is an indefinite subtype if it is an unconstrained array subtype, or if it has unknown discriminants or unconstrained discriminants without defaults (see 3.7); otherwise, the subtype is a definite subtype (all elementary subtypes are definite subtypes)." http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-3.html#I1468 (Although the ARM isn't very good for learning the language, once you have a grasp of the language, it can be helpful for investigating specific topics like this.) In simple terms, a subtype is definite if you can declare a variable of the subtype without giving any additional information, and indefinite if you can't. So, since you can't say S : String; String is indefinite; you have to give additional information (the bounds for S) either explicitly S : String (1 .. 6); or through initialization S : String := Ada.Text_IO.Get_Line; Similarly, given a record type with discriminants without defaults type Rec (Max : Positive) is record Len : Natural := 0; Val : String (1 .. Max) := (1 .. Max => ' '); end record; you can't say R : Rec; so Rec is indefinite. You have to provide a value for Max somehow. The unknown discriminant notation (<>) is used with a private type in a pkg to force clients to provide initialization for objects of the type package P is type T (<>) is private; function F return T; private -- P ... end P; It's also used for generic formal types to indicate that an instantiation of the generic won't do anything with the type that can't be done with an indefinite type, so it may be instantiated with an indefinite actual type. generic -- G type T (<>) is private; package G is ... end G; -- Jeff Carter "I used to manufacture escalator shoes for people who were nauseous in elevator shoes." Take the Money and Run 142