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,ae138939b724a2de X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!q12g2000prb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Single element arrays as function parameters Date: Fri, 10 Jun 2011 14:58:40 -0700 (PDT) Organization: http://groups.google.com Message-ID: <529356dd-fe4a-4dc0-9415-16ebdb5f611d@q12g2000prb.googlegroups.com> References: <86ei31v43e.fsf@gareth.avalon.lan> <86aadpv0jp.fsf@gareth.avalon.lan> 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 1307743120 23174 127.0.0.1 (10 Jun 2011 21:58:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 10 Jun 2011 21:58:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q12g2000prb.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ 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; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:20710 Date: 2011-06-10T14:58:40-07:00 List-Id: On Jun 10, 2:28=A0pm, Mart van de Wege wrote: > "J-P. Rosen" writes: > > Le 10/06/2011 22:11, Mart van de Wege a =E9crit : > > >> M :=3D Init.Creature( Name =3D> "Dwarf", > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Creature_Type =3D> Humanoi= d, > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Creature_Subtype =3D> (Dwa= rf) ); > > >> The above call fails to compile: > > >> test_create.adb:13:45: positional aggregate cannot have one component > > This is the clue: it is interpreted as a parenthesized value, not as an > > aggregate. Just write: > > > =A0M :=3D Init.Creature( Name =3D> "Dwarf", > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Creature_Type =3D> = Humanoid, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Creature_Subtype = =3D> (1 =3D> Dwarf) ); > > Brrr. That works, but it looks a bit...ugly. Especially considering that > creatures only having one subtype[1] is the norm in Dungeons&Dragons > (the application in question is meant to help manage large amounts of > data to assist in running a campaign). > > If there is no more elegant solution, I'll fix this by adding the > necessary remarks to the API description, in the unlikely case that > someone else except me is ever interested in this application. Your original post doesn't make sense; it defines a function Creature with parameters Name, Race, Level, and Player, but then you're calling a function Creature that has parameters Name, Creature_Type, and Creature_Subtype. Actually, though, this would explain some of the error messages in your original post (such as missing "Race" and "Level" arguments). Assuming you meant something like Race =3D> (Dwarf) one solution is to define an overloaded Creature function that takes a single element instead of an array. Assuming MM_Subtype is an array of Element_Type (since I don't know what the actual name is), you can write something like function Creature (Name : in String; Race : in Element_Type; Level : in Positive; Player : in String) return Character_Ptr is begin return Creature (Name =3D> Name, Race =3D> (1 =3D> Race), Level =3D> Level, Player =3D> Player); end Creature; and now the rest of your program can call Creature with either a single element or an array as the Race. (And you wouldn't need to parenthesize the single element when you call it, but you could.) -- Adam