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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2bbd7f65ab12f156 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!x35g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Q: how to copy contents and use ancestor's constraints at the same time ? Date: Mon, 13 Aug 2007 14:33:42 -0700 Organization: http://groups.google.com Message-ID: <1187040822.123740.52460@x35g2000prf.googlegroups.com> References: <46c0c9e8$1_3@news.bluewin.ch> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1187040823 20094 127.0.0.1 (13 Aug 2007 21:33:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 13 Aug 2007 21:33:43 +0000 (UTC) In-Reply-To: <46c0c9e8$1_3@news.bluewin.ch> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: x35g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1430 Date: 2007-08-13T14:33:42-07:00 List-Id: On Aug 13, 2:16 pm, Gautier wrote: > Hello! > > In the procedure below, how to do [A] and [B] together, and is there a way not > to have to write the constraints, like when constraining an object by > initializing it with a value of the same type ? > > Thanks in advance! > NB: I looked in a book, but maybe not hard enough ;-) > ----- > procedure Test_Ancestor_copy is > > type Index_array_type is array(Positive range <>) of Natural; > > type PF_Data( > n1: Natural; > n2: Natural; > n3: Natural > ) > is > tagged record > p1 : Index_array_type(1..n1); > p2 : Index_array_type(1..n2); > p3 : Index_array_type(1..n3); > end record; > > function Read return PF_Data is > begin > return > (n1 => 1, > n2 => 2, > n3 => 3, > p1 => (1=>1), > p2 => (1,2), > p3 => (1,2,3) > ); > end Read; > > type PF is new PF_Data with record > computed: Boolean:= False; > result: Float; > end record; > > initial_pf: constant PF_Data:= Read; > > work_pf: PF( > n1 => initial_pf.n1, > n2 => initial_pf.n2, > n3 => initial_pf.n3 > ); > -- [A] work_pf sized with initial_pf constraints > > begin > PF_Data(work_pf):= initial_pf; -- [B] copy base data > end; My first thought (using Ada 2005) is work_pf : PF := (initial_pf with others => <>); But I haven't looked through all the language rules to make sure this is legal. -- Adam