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,943350d29d278e69,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsgate.cuhk.edu.hk!news.netfront.net!not-for-mail From: Marek Janukowicz Newsgroups: comp.lang.ada Subject: Generic package with dynamic subprogram name? Followup-To: comp.lang.ada Date: Thu, 10 Jun 2010 01:07:03 +0200 Organization: Starware Message-ID: NNTP-Posting-Host: 89.174.12.152 Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: adenine.netfront.net 1276124828 23254 89.174.12.152 (9 Jun 2010 23:07:08 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Wed, 9 Jun 2010 23:07:08 +0000 (UTC) User-Agent: KNode/4.4.3 X-Original-Bytes: 2543 Xref: g2news1.google.com comp.lang.ada:11541 Date: 2010-06-10T01:07:03+02:00 List-Id: 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 ---