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!s33g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors Update_Element issue Date: Tue, 13 May 2008 10:55:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4bb8bb12-225b-4790-bd12-40ef0b0adeaf@s33g2000pri.googlegroups.com> References: 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 1210701321 4367 127.0.0.1 (13 May 2008 17:55:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 May 2008 17:55:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s33g2000pri.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:56 Date: 2008-05-13T10:55:21-07:00 List-Id: On May 13, 10:26 am, S=E9bastien wrote: > Hi, > > I'm trying to use the Ada.Containers.Vectors librairies, but I don't > know how to update element using a context. > > I have a list of element and I want to use Update_Element with a > procecedure Update_Element_Process, however I want to add static > argument to the Update_Element_Process. > > This could be something like : > > procedure My_Update(c: in out context; Element: in out Element_Type); > > and then > > procedure Update_All(c: in out context) is > begin > my_list.Update_Element(1, My_Update'Access); > end; > > Because My_Update is not exacly the type Update_Element_Process it's nor > working. 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.) > type Update_Element_Process is > access procedure (Element : in out Element_Type); > > Note that generic doesn't help : they give me a bug error compilation > because of Address invalid of the generic instance. > > I tried this: > generic > c: Context; > procedure My_Update_Generic(Element: in out Element_Type); > > procedure Update_All(c: in out context) is > procedure My_Update is new My_Update_Generic(c =3D> c); > begin > my_list.Update_Element(1, My_Update'Access); > end; > > That's not working and I can understand it ;-) No dynamical address > since the generic will instancied at runtime or something like that ... Offhand, I *don't* understand why this wouldn't work. It seems like it should. Is the compiler giving you an error message, or are you getting exceptions or bad behavior at runtime? But you shouldn't need a generic; the nested procedure solution should work fine. -- Adam