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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,85d5a13738392342,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!a7g2000vby.googlegroups.com!not-for-mail From: Simon Belmont Newsgroups: comp.lang.ada Subject: Unknown discriminants with nested records Date: Thu, 16 Jun 2011 16:53:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1e197c14-a2ff-4867-85be-fda06a10e37b@a7g2000vby.googlegroups.com> NNTP-Posting-Host: 24.218.138.255 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1308268404 17417 127.0.0.1 (16 Jun 2011 23:53:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Jun 2011 23:53:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a7g2000vby.googlegroups.com; posting-host=24.218.138.255; posting-account=ShYTIAoAAABytvcS76ZrG9GdaV-nXYKy User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; InfoPath.2),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:20869 Date: 2011-06-16T16:53:09-07:00 List-Id: New to ada (2005), and trying to figure out how to create records of other records with unknown discriminants, e.g. like this: package Test_Package is type Foo_Type (<>) is limited private; -- some record with unknown discriminants. t1: Foo_Type := MakeAFooType; -- works fine being built by a function type BarType is record B1: Integer; -- other record elements B2: FooType := MakeAFooType; -- Error, unconstrained subtype. end record; private type FooType is limited record F1: Integer; end record; end Test_Package; The (<>) seems to be the defacto way to limit creation to a function, yet it seemingly precludes you from using it in a nested record. It seems strange that there is the ability to declare a standalone object of that type, but trying to nest one within another record throws an "unconstrained subtype" error; if it knows the constraints one place, why doesn't it know them several lines down? I have tried all the various syntaxes I can find, but nothing seems to work (though it wouldn't be the first time there was some esoteric syntax that escaped me). So, that being said: 1. What is the appropriate syntax to do this? 2. If not, what is the technical reason and design decision why? 3. Are there workarounds? 4. Am I programming Ada the wrong way? (this happens often) 4. Can anyone point me to the section in the LRM that specifies this either way? Thanks