comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Language question : function'Access / function'unchecked_Access
Date: 1998/11/24
Date: 1998-11-24T00:00:00+00:00	[thread overview]
Message-ID: <m3ww4l73w9.fsf@mheaney.ni.net> (raw)
In-Reply-To: ek1BDX5F#GA.291@nih2naac.prod2.compuserve.com

"Didier DOUSSAUD" <d_doussaud@csi.com> writes:

> I write a list package and need a Seach function that return the "Index" of
> the object that match some condition.
> 
> (the condition is coded in a function that have for parameter the item of
> the list and return the boolean result of the test )
> 
> Impossible to call the Search function ????

For esoteric reasons, you can't call a locally declared function via
T'Access.  You can't even use T'Unchecked_Access.

Yes, this is a bummer, but that's the rule.

Go to DejaNews and search for "downward closures" on comp.lang.ada.  The
reasons for this limitation of the language have been discussed often.

However, all is not lost:

1)  If you're using gnat, then you can do what you want by using the
    attribute T'Unrestricted_Access.


    I := Search( L, Match'Unrestricted_Access );


2)  It _is_ of course possible to call a locally declared subprogram, if
    it's imported as a generic formal parameter:

package P_List is
  type Item is null record;
  type List is null record;
  type Index is null record;

  generic
    with Funct ( I : Item ) return Boolean;
  function Generic_Search 
    ( L : List ) 
    return Index;

end P_List;

 with P_List; use P_List;
 procedure Test_Callback is
   L : List;
   I : Index;

   function Match( I : Item ) return Boolean is
   begin
     return True;
   end;

   function Search is 
     new Generic_Search (Match);
   
 begin

    I := Search (L);


This does what you require.







  reply	other threads:[~1998-11-24  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-24  0:00 Language question : function'Access / function'unchecked_Access Didier DOUSSAUD
1998-11-24  0:00 ` Matthew Heaney [this message]
1998-11-25  0:00 ` Pascal Obry
replies disabled

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