comp.lang.ada
 help / color / mirror / Atom feed
From: Marek Janukowicz <marek@janukowicz.net>
Subject: Generic package with dynamic subprogram name?
Date: Thu, 10 Jun 2010 01:07:03 +0200
Date: 2010-06-10T01:07:03+02:00	[thread overview]
Message-ID: <hup6qr$mmm$1@adenine.netfront.net> (raw)

Hello

(Disclaimer: the code won't compile and some parameters are omitted, but 
everyone should get the idea).

I need a number of function/procedure pairs and generics seem to be the way 
to go.

I can use something like this:
generic
  Attr : String;
function Get_Attribute return String;
generic
  Attr : String;
procedure Set_Attribute ( Value : String );

and instantiate:
function Get_First_Name is new Get_Attribute( "FirstName" );
procedure Set_First_Name is new Set_Attribute( "FirstName" );
function Get_Last_Name is new Get_Attribute( "LastName" );
procedure Set_Last_Name is new Set_Attribute( "LastName" );

However, I don't like passing the same parameters to instantiation of both 
the function and the procedure (as mentioned earlier there are more 
parameters and they are always the same for Get/Set instantiations). So I 
came up with something like this:

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( ... );

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? I will also appreciate 
suggestions of different approaches, as I didn't program in Ada for a few 
years now and I can't say I know the language well.

Thanks
-- 
Marek Janukowicz

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---



             reply	other threads:[~2010-06-09 23:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-09 23:07 Marek Janukowicz [this message]
2010-06-09 23:37 ` Generic package with dynamic subprogram name? Jeffrey R. Carter
2010-06-10  6:05   ` Ludovic Brenta
2010-06-10  7:33 ` Stephen Leake
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