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-Thread: 103376,42795ada22dedd1b,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!a39g2000hsc.googlegroups.com!not-for-mail From: malaise@magic.fr Newsgroups: comp.lang.ada Subject: Legal usage of downward closures Date: Thu, 16 Aug 2007 09:11:18 -0700 Organization: http://groups.google.com Message-ID: <1187280678.505830.294720@a39g2000hsc.googlegroups.com> NNTP-Posting-Host: 192.54.144.229 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1187280678 14493 127.0.0.1 (16 Aug 2007 16:11:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Aug 2007 16:11:18 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 webshield1.thalesgroup.com Complaints-To: groups-abuse@google.com Injection-Info: a39g2000hsc.googlegroups.com; posting-host=192.54.144.229; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1461 Date: 2007-08-16T09:11:18-07:00 List-Id: Hi, I have problems understanding the RAT05 section on downward closures. I thought that anonymous access to a sub-program, as parameter of a sub-program, would prevent local copies and further usage out of scope. Surprisingly, the following example compiles an runs (on GNAT GPL 2007). package Pack is procedure Store (Arg : access procedure); procedure Call; end Pack; package body Pack is Acc1 : access procedure; type Acc_Type is access procedure; Acc2 : Acc_Type; procedure Store (Arg : access procedure) is begin Acc1 := Arg; Acc2 := Arg; end Store; procedure Call is begin Acc1.all; Acc2.all; end Call; end Pack; -------------------------------------- with Ada.Text_Io; with Pack; procedure Tes is begin declare I : Integer := 21; procedure Proc is begin Ada.Text_Io.Put_Line ("In Proc" & I'Img); end Proc; begin Pack.Store (Proc'Access); end; declare I : Integer := 22; begin Pack.Call; end; end Tes; This produces the output: In Proc 21 In Proc 21 despite my attempt to "overwrite" 21 by 22 :-) So it seems that the feature is rather to guarantee persistence of the referenced sub-program and its scope as long as a reference to it is stored somewhere. Is it so much "magic"? How long are Proc and I=21 kept in memory for further calls to "Call". Are they cleared if I call Pack.Store with an access to another procedure? Thank's