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,ed290afd6f09a679 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Initialize with aggregate? Date: 22 Nov 2005 08:57:23 -0800 Organization: http://groups.google.com Message-ID: <1132678643.906071.122770@z14g2000cwz.googlegroups.com> References: <1132602018.206322.285630@g44g2000cwa.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1132678649 14634 127.0.0.1 (22 Nov 2005 16:57:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 22 Nov 2005 16:57:29 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news1.google.com comp.lang.ada:6528 Date: 2005-11-22T08:57:23-08:00 List-Id: Robert A Duff wrote: > ejijott@gmail.com writes: > > > Hi there! > > > > Regarding the code below, what syntax do I use to initialize tempstore > > with an aggregate? > > [code] > > . > > . > > . > > type node; > > type storage is access node; > > type node is > > record > > next: storage; -- Pekare till n=E4sta nod. > > item: string(1..50); -- En textstr=E4ng > > len: integer :=3D-1; -- L=E4ngden p=E5 str=E4ngen. > > count: integer :=3D 0; -- Antalet f=F6rekomster av str=E4n= gen > > end record; > > . > > . > > . > > tempstore:=3Dnew Node; > > tempstore.item(1 .. Val'length):=3DVal; > > tempstore.len:=3DVal'length; > > tempstore.count:=3D1; > > if S /=3D null then > > tempstore.next:=3DS; > > end if; > > S:=3Dtempstore; > > [/code] > > How about something like this: > > type node; > type storage is access node; > type node(len: natural) is > record > next: storage; -- Pekare till n=E4sta nod. > item: string(1..len); -- En textstr=E4ng > count: integer :=3D 0; -- Antalet f=F6rekomster av str=E4ngen > end record; > > tempstore:=3Dnew Node'( > len =3D> val'length, > next =3D> S, > item =3D> val, > count =3D> 1); > S:=3Dtempstore; > > Hardwiring Item'Length to 50 isn't a good idea, and it makes the > programming harder, because you have to carefully avoid the junk > at the end. I don't see how you can make a blanket statement like this. If you code it the way you've shown, you can't change "len" in a node once you've allocated it. But sometimes changing "item" and "len" in an existing node to change the length of the string, without changing the other fields in the node, is what you want to do, so there are cases where the original poster's implementation is more appropriate than using a discriminant record. (Using Ada.Strings.Bounded may make programming easier still, but you still have to hardwire a maximum length.) -- Adam