From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Generic package with dynamic subprogram name?
Date: Thu, 10 Jun 2010 03:33:11 -0400
Date: 2010-06-10T03:33:11-04:00 [thread overview]
Message-ID: <82eigfnxzc.fsf@stephe-leake.org> (raw)
In-Reply-To: hup6qr$mmm$1@adenine.netfront.net
Marek Janukowicz <marek@janukowicz.net> writes:
> generic
> Attr : String;
> package Get_Set is
> function Get_Attribute return String;
> procedure Set_Attribute ( Value : String );
> end Get_Set;
>
> But if I then instantiate:
> package Get_Set_First_Name is new Get_Set( "FirstName" );
> package Get_Set_Last_Name is new Get_Set( "LastName" );
>
> subprogram names will overlap. I know I can call them using package prefix,
> but I'd really like to have nice API like here:
> Get_First_Name( ... );
> Set_Last_Name( ... );
Use better names for the generic, so the package prefix is not just noise:
generic
Attribute : String;
package Attributes is
function Get return String;
procedure Set ( Value : String );
end Get_Set;
package First_Name is new Attributes( "FirstName" );
package Last_Name is new Attributes( "LastName" );
First_Name.Get( ... );
Last_Name.Set( ... );
> I understand things I ask about in the subject are most likely not possible,
> but is there any other way to achieve what I want?
Renames was suggested. Writing all of those can get tedious, and
probably defeats the purpose of the generic.
Using an ASIS application to generate code would be another way.
--
-- Stephe
next prev parent reply other threads:[~2010-06-10 7:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 23:07 Generic package with dynamic subprogram name? Marek Janukowicz
2010-06-09 23:37 ` Jeffrey R. Carter
2010-06-10 6:05 ` Ludovic Brenta
2010-06-10 7:33 ` Stephen Leake [this message]
2010-06-10 10:14 ` Brian Drummond
2010-06-10 10:48 ` Yannick Duchêne (Hibou57)
2010-06-10 12:13 ` sjw
2010-06-11 9:08 ` Stephen Leake
2010-06-11 9:55 ` J-P. Rosen
2010-06-11 12:19 ` Brian Drummond
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox