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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-28 10:45:37 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!news.tufts.edu!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Anybody in US using ADA ? One silly idea.. User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Tue, 28 Jan 2003 18:44:55 GMT Content-Type: text/plain; charset=us-ascii References: <1041908422.928308@master.nyc.kbcfp.com> <1041997309.165001@master.nyc.kbcfp.com> <1042086217.253468@master.nyc.kbcfp.com> <1042477504.547640@master.nyc.kbcfp.com> <3E32B5C0.5090004@attbi.com> <1043684990.403565@master.nyc.kbcfp.com> Hyman Rosen writes: > Robert A Duff wrote: > > No, because you can't pass a nested procedure to a less-nested > > procedure. > > So you can instantiate a generic procedure and pass its address > to a less-nested procedure, even though the generic uses procedures > defined at a more-nested level? No. You can pass a nested procedure to a less-nested generic during instantiation. You cannot pass the 'Access of a nested procedure to a less-nested procedure. generic with procedure Action(Item: Element); procedure Iterate(X: Data_Structure); -- Calls Action once for each Item in the data structure. function Count(X: Data_Structure) return Natural is Result: Natural := 0; procedure Incr_Result(Item: Element) is begin Result := Result + 1; end; procedure Iter is new Iterate(Incr_Result); begin Iter(X); return Result; end Count; The above works fine (barring typos -- I didn't compile it). But if you try to do the same thing using access-to-procedure, it won't work: type Action_Proc is access procedure(Item: Element); procedure Iterate(X: Data_Structure; Action: Action_Proc); function Count(X: Data_Structure) return Natural is Result: Natural := 0; procedure Incr_Result(Item: Element) is begin Result := Result + 1; end; begin Iterate(X, Incr_Result'Access); -- Illegal! return Result; end Count; - Bob