comp.lang.ada
 help / color / mirror / Atom feed
* Generic package with dynamic subprogram name?
@ 2010-06-09 23:07 Marek Janukowicz
  2010-06-09 23:37 ` Jeffrey R. Carter
  2010-06-10  7:33 ` Stephen Leake
  0 siblings, 2 replies; 10+ messages in thread
From: Marek Janukowicz @ 2010-06-09 23:07 UTC (permalink / 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 ---



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-06-11 12:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox