From: Adam Beneschan <adam@irvine.com>
Subject: Re: Single element arrays as function parameters
Date: Fri, 10 Jun 2011 14:58:40 -0700 (PDT)
Date: 2011-06-10T14:58:40-07:00 [thread overview]
Message-ID: <529356dd-fe4a-4dc0-9415-16ebdb5f611d@q12g2000prb.googlegroups.com> (raw)
In-Reply-To: 86aadpv0jp.fsf@gareth.avalon.lan
On Jun 10, 2:28 pm, Mart van de Wege <mvdw...@mail.com> wrote:
> "J-P. Rosen" <ro...@adalog.fr> writes:
> > Le 10/06/2011 22:11, Mart van de Wege a écrit :
>
> >> M := Init.Creature( Name => "Dwarf",
> >> Creature_Type => Humanoid,
> >> Creature_Subtype => (Dwarf) );
>
> >> 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:
>
> > M := Init.Creature( Name => "Dwarf",
> > Creature_Type => Humanoid,
> > Creature_Subtype => (1 => 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 => (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 => Name, Race => (1 => Race), Level =>
Level, Player => 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
next prev parent reply other threads:[~2011-06-10 21:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-10 20:11 Single element arrays as function parameters Mart van de Wege
2011-06-10 20:54 ` J-P. Rosen
2011-06-10 21:28 ` Mart van de Wege
2011-06-10 21:58 ` Adam Beneschan [this message]
2011-06-10 22:24 ` Mart van de Wege
2011-06-11 12:28 ` Peter C. Chapin
2011-06-13 14:49 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox