comp.lang.ada
 help / color / mirror / Atom feed
* Instantiating a generic formal procedure with an access procedure value
@ 1999-12-31  0:00 Jeff Carter
  2000-01-03  0:00 ` Tucker Taft
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Carter @ 1999-12-31  0:00 UTC (permalink / raw)


Here's something that I haven't been able to figure out from the ARM.
No doubt I haven't looked in the right place yet.

Suppose I have a package that provides an unprotected structure
(normally this would be a generic package, but that's not important for
this example):

package S_U is
   type Handle is limited private;

   procedure Op (Item : in out Handle; Item : in Integer);

   generic -- Iterate
      with procedure Action
         (Element : in out Integer; Continue : out Boolean);
   procedure Iterate (Over : in out Handle);
private -- S_U
   ...
end S_U;

Suppose I now want to use this package to create a protected structure:

with S_U;
package S is
   type Action_Ptr is access procedure
      (Element : in out Integer; Continue : out Boolean);

   protected type Handle is
      procedure Op (Element : in Integer);
      procedure Iterate (Action : in Action_Ptr);
   private -- Handle
      Data : S_U.Handle;
   end Handle;
end S;

package body S is
   protected body Handle is
      procedure Op (Element : in Integer) is
      begin -- Op
         S_U.Op (Item => Data, Element => Element);
      end Op;

      procedure Iterate (Action : in Action_Ptr) is
         procedure Local is new S_U.Iterate (Action => ???);
         -- What do I use here?
      begin -- Iterate
         Local (Over => Data);
      end Iterate;
   end Handle;
end S;

Neither Action nor Action.all will compile here. The only thing I've
found that will compile is

procedure Iterate (...) is
   procedure Dummy (Element : in out Integer; Continue : out Boolean) is
   begin -- Dummy
      Action (Element => Element, Continue => Continue);
   end Dummy;

   procedure Local is new S_U.Iterate (Action => Dummy);
begin -- Iterate
   Local (Over => Data);
end Iterate;

Hopefully there's a way to avoid this extra procedure call.
--
Jeff Carter
"Now go away or I shall taunt you a second time."
-- Monty Python and the Holy Grail


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-01-14  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-31  0:00 Instantiating a generic formal procedure with an access procedure value Jeff Carter
2000-01-03  0:00 ` Tucker Taft
2000-01-04  0:00   ` Jeff Carter
2000-01-04  0:00     ` Tucker Taft
2000-01-05  0:00       ` Jeff Carter
2000-01-05  0:00         ` Ed Falis
2000-01-12  0:00         ` Jeff Carter
2000-01-12  0:00           ` Simon Wright
2000-01-13  0:00             ` Jeff Carter
2000-01-13  0:00               ` Simon Wright
2000-01-13  0:00               ` Tucker Taft
2000-01-14  0:00                 ` Jeff Carter

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