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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6d47794b76bd8d3f X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Language question : function'Access / function'unchecked_Access Date: 1998/11/24 Message-ID: #1/1 X-Deja-AN: 415126336 Sender: matt@mheaney.ni.net References: NNTP-Posting-Date: Tue, 24 Nov 1998 02:58:56 PDT Newsgroups: comp.lang.ada Date: 1998-11-24T00:00:00+00:00 List-Id: "Didier DOUSSAUD" 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.