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,5bbcbfbb228d6549 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!l28g2000prd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors Update_Element issue Date: Wed, 14 May 2008 08:17:36 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8d5f96c4-9a65-4e99-bc1b-a281a547e213@l28g2000prd.googlegroups.com> References: <4bb8bb12-225b-4790-bd12-40ef0b0adeaf@s33g2000pri.googlegroups.com> <482AFEAC.3040306@gmail.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1210778256 30323 127.0.0.1 (14 May 2008 15:17:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 14 May 2008 15:17:36 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l28g2000prd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:60 Date: 2008-05-14T08:17:36-07:00 List-Id: On May 14, 8:01 am, S=E9bastien wrote: > > procedure Update_All (c : in out context) is > > > procedure Do_The_Update (Element : in out Element_Type) is > > begin > > My_Update (c, Element); > > end Do_Update; > > begin > > my_list.Update_Element (1, Do_The_Update'Access); > > end Update_All; > > > I haven't tried this. However, it should work because the Process > > parameter to Update_Element is declared as an anonymous access- > > procedure type, rather than as a named access-procedure type, and this > > means you can pass a nested procedure access to it without any > > accessibility-level issues. (This sort of usage is exactly why > > anonymous access-subprograms types were added to Ada 2005.) > > Ok I didn't think about nested proc having access to argument. When you > mean anonymous access, you are meaning "Do_The_Update'Access"? There was > no procedure access in previous ada version? What I mean is that the procedure is declared with an anonymous access subprogram parameter. Here's the declaration of Update_Element in the Vectors package: procedure Update_Element (Container : in out Vector; Index : in Index_Type; Process : not null access procedure (Element : in out Element_Type)); The declaration of Process is "not null access procedure". This is an *anonymous* access because the access type isn't given a name. In Ada 95, you would have to make this a named access type: type Process_Type is access procedure (Element : in out Element_Type); -- "not null" didn't exist in Ada 95 procedure Update_Element (Container : in out Vector; Index : in Index_Type; Process : in Process_Type); You can still do this in Ada 2005, but if you do, you would only be allowed to pass Proc'Access as a parameter if Proc was a *global* procedure (not nested inside any other procedure). The reason is that Update_Element could save Process in some global variable. Sometimes that's what you want---you want to be able to save a procedure access and use it later. But in the actual declaration, the Process parameter is of an anonymous access type, which means that you can pass an 'Access of any procedure, no matter how nested it is, but Update_Element can't save the procedure access in a variable anywhere. Hope that explains things. > Anyway it's working fine. Great! -- Adam