comp.lang.ada
 help / color / mirror / Atom feed
* Language question : function'Access / function'unchecked_Access
@ 1998-11-24  0:00 Didier DOUSSAUD
  1998-11-24  0:00 ` Matthew Heaney
  1998-11-25  0:00 ` Pascal Obry
  0 siblings, 2 replies; 3+ messages in thread
From: Didier DOUSSAUD @ 1998-11-24  0:00 UTC (permalink / raw)


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 ????

Look the following sample may be more explicit than my poor english...

Thanks
Didier
d_doussaud@csi.com

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

  type Search_Function is access function ( I : Item ) return Boolean;

  function Search( L : List; Funct : Search_Function ) 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;
begin

  -- this line :
  I := Search( L, Match );
  -- generate the ERROR :
  --    The Accessibility Level of The Subprogram Denoted By The The Prefix
  --    Shall not Be Statically Deeper Than That of The Expected type
  -- I can understand this

  -- but this line :
  I := Search( L, Match'Unchecked_Access );
  -- generate the ERROR :
  --    The prefix of Unchecked_Access, which is function name, has no
  --    interpretation as A Parameterless function Call
  -- ????

  -- is it possible to do what I want in ADA ?
end;













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

* Re: Language question : function'Access / function'unchecked_Access
  1998-11-24  0:00 Language question : function'Access / function'unchecked_Access Didier DOUSSAUD
@ 1998-11-24  0:00 ` Matthew Heaney
  1998-11-25  0:00 ` Pascal Obry
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 1998-11-24  0:00 UTC (permalink / raw)


"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.







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

* Re: Language question : function'Access / function'unchecked_Access
  1998-11-24  0:00 Language question : function'Access / function'unchecked_Access Didier DOUSSAUD
  1998-11-24  0:00 ` Matthew Heaney
@ 1998-11-25  0:00 ` Pascal Obry
  1 sibling, 0 replies; 3+ messages in thread
From: Pascal Obry @ 1998-11-25  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2628 bytes --]

Didier,

You can't do that, the compiler is right !

There is many solutions. Two of them have been described by Matthew Heaney.

The other solution is to put you Match function in a separate package. This
way you don't
have the problem of "Accessiblility Level".

Pascal.

Didier DOUSSAUD a �crit dans le message ...
>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 ????
>
>Look the following sample may be more explicit than my poor english...
>
>Thanks
>Didier
>d_doussaud@csi.com
>
>--------------------------------------------------------------------
>package P_List is
>  type Item is null record;
>  type List is null record;
>  type Index is null record;
>
>  type Search_Function is access function ( I : Item ) return Boolean;
>
>  function Search( L : List; Funct : Search_Function ) 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;
>begin
>
>  -- this line :
>  I := Search( L, Match );
>  -- generate the ERROR :
>  --    The Accessibility Level of The Subprogram Denoted By The The Prefix
>  --    Shall not Be Statically Deeper Than That of The Expected type
>  -- I can understand this
>
>  -- but this line :
>  I := Search( L, Match'Unchecked_Access );
>  -- generate the ERROR :
>  --    The prefix of Unchecked_Access, which is function name, has no
>  --    interpretation as A Parameterless function Call
>  -- ????
>
>  -- is it possible to do what I want in ADA ?
>end;


--|------------------------------------------------------------
--| Pascal Obry                               Team-Ada Member |
--|                                                           |
--| EDF-DER-IPN-SID- T T I                                    |
--|                       Intranet: http://cln46gb            |
--| Bureau N-023            e-mail: pascal.obry@edfgdf.fr     |
--| 1 Av G�n�ral de Gaulle  voice : +33-1-47.65.50.91         |
--| 92141 Clamart CEDEX     fax   : +33-1-47.65.50.07         |
--| FRANCE                                                    |
--|------------------------------------------------------------
--|
--|   http://ourworld.compuserve.com/homepages/pascal_obry
--|
--|   "The best way to travel is by means of imagination"







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

end of thread, other threads:[~1998-11-25  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-24  0:00 Language question : function'Access / function'unchecked_Access Didier DOUSSAUD
1998-11-24  0:00 ` Matthew Heaney
1998-11-25  0:00 ` Pascal Obry

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