comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Signature Package With Generic Proceedure
Date: Sun, 22 Jul 2012 17:45:08 -0700 (PDT)
Date: 2012-07-22T17:45:08-07:00	[thread overview]
Message-ID: <93f32ea9-a61d-4148-83be-258ae0676cac@googlegroups.com> (raw)
In-Reply-To: <88734b25-68e5-42b2-89ea-0c0e3fc9fbc5@googlegroups.com>

On Sunday, July 22, 2012 9:22:55 AM UTC-7, Keean Schupke wrote:
> 
> Why would you want to? Easy... You use signature packages to decouple the 
> implementation from the interface, so that other packages can decide which
> implementation to use.

Well, "signatures" are hardly the only way to decouple things, and in practice, of all the possible methods there are to decouple implementations from interfaces, signature packages are probably the last method I would choose.  Do you come from some other language background where the "signature" concept is more common?  Whatever language that is, it sounds like the concept isn't as integral to Ada as it is in your other language.  Because of that, it took me a pretty long time to figure out what you were trying to accomplish.

In fact, in the examples you provide, signatures seem completely unnecessary and confusing.  You appear to have defined a package Disjointset_Signature whose only generic formal is one type.  Presumably, you then define generic packages with formals like

   generic
       with package The_Signature is new Disjointset_Signature;
   procedure Algorithm (Set : in out The_Signature.Set_Type);

But to me, this is a lot more confusing than just declaring

   generic
       type Set_Type is private;
   procedure Algorithm (Set : in out Set_Type);

Generic signatures may have their uses, but I don't think they're all that common in the Ada world.

OK, with that rant out of the way: I think I finally figured out what you were trying to do.  You're trying to declare a generic procedure GP that is parameterized with code from some other procedure P specified by the user, but where P itself needs to be parameterized with another piece of code internal to GP.  And you'd like to do this in a way that allows everything to be done inline, so that a compiler that performs macro-expansion when instantiating  generics (not all do) can generate a procedure Update that includes both code from P and code supplied by GP.

That's an interesting concept, but it isn't supported by Ada, and I can't think of a way to do it.  Furthermore, since what you want can easily be accomplished (but not as efficiently) by access-to-procedures, I'm not sure that it's a good candidate for a new language feature.  Sorry.  You're probably better off asking your compiler vendor for some implementation-defined pragmas to help with this (e.g. if the compiler knows, because of a pragma, that Update will only be called with the 'Access of one known procedure, then the compiler could generate code that doesn't have to use indirect subprogram calls and could inline the known procedure).

                           -- Adam



  reply	other threads:[~2012-07-26 16:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <045f7b44-2a4a-4292-80fd-0b6bc8ee3465@googlegroups.com>
2012-07-21 22:22 ` Signature Package With Generic Proceedure Adam Beneschan
2012-07-22  7:28   ` Dmitry A. Kazakov
2012-07-22 16:22   ` Keean Schupke
2012-07-23  0:45     ` Adam Beneschan [this message]
     [not found]       ` <79925d0c-b2dd-44a3-9451-48f0ee19485f@googlegroups.com>
     [not found]         ` <500d3a9d$0$6566$9b4e6d93@newsspool4.arcor-online.net>
2012-07-23 18:29           ` Keean Schupke
     [not found]         ` <ac8bfaed-dbcc-491a-a760-c25672445eef@googlegroups.com>
2012-07-23 19:41           ` Keean Schupke
2012-07-24  2:57         ` Randy Brukardt
     [not found]         ` <jul2n4$af5$1@munin.nbi.dk>
2012-07-24  8:02           ` Keean Schupke
2012-07-24  8:43             ` Dmitry A. Kazakov
2012-07-24  8:59               ` Keean Schupke
2012-07-23 10:26 ` Simon Wright
2012-07-23 18:36   ` Keean Schupke
replies disabled

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