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,330ec86e1824a689 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-28 15:47:44 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uunet!sea.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Run-Time Type Assignment Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Wed, 28 Aug 2002 22:47:13 GMT References: <5ee5b646.0208280304.614d11fc@posting.google.com> NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:28533 Date: 2002-08-28T22:47:13+00:00 List-Id: "Frank J. Lhota" writes: > "Robert A Duff" wrote in message > news:wccn0r7hx5y.fsf@shell01.TheWorld.com... > > Kilgallen@SpamCop.net (Larry Kilgallen) writes: > > > > > What is a downward closure ? > > > > The ability to pass a procedure as a parameter to a procedure. > > > > > GNAT supports downward closures via the 'Unrestricted_Access attribute, > > but that's not Ada (unfortunately). > > What about using just the plain old 'Access attribute to pass a pointer to > the procedure as a parameter? That is supported by all Ada 95 compilers. No, 'Access doesn't work. Typically, the loop body (the procedure to be passed as a parameter) is more nested than the iterator, which makes 'Access illegal. function Count_Items(X: Container) return Natural is Result: Natural := 0; procedure Incr(...) is begin Result := Result + 1; end Incr; begin Iterate(X, Incr'Access); -- Wrong! return Result; end Count_Items; That's illegal, because Incr is more nested than the access-to-procedure type passed to the iterator (which is defined in some package elsewhere). Usually, the loop body (e.g. Incr) needs to be more nested so it can see some local variables. GNAT's 'Unrestricted_Access attribute works in this case, but it is nonportable and dangerous. The question was whether Pascal supports features not supported by Ada: in this case, it does; the feature is portable and safe (compared to 'Unrestricted_Access). It's more readable, too, since you can just pass the procedure, not a pointer to it. - Bob