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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c08a7609345f4e5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!x42g2000yqx.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Limited use for limited with? Date: Tue, 28 Sep 2010 15:04:28 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <853314bc-0f79-435f-86a5-d7bcdd610731@c10g2000yqh.googlegroups.com> <36e886fa-b272-461f-bf86-a6b18366b64f@i5g2000yqe.googlegroups.com> <7acf7226-e945-4683-b8a6-ca66f07fe7a1@j24g2000yqa.googlegroups.com> NNTP-Posting-Host: 85.1.245.123 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1285711469 5455 127.0.0.1 (28 Sep 2010 22:04:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 28 Sep 2010 22:04:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x42g2000yqx.googlegroups.com; posting-host=85.1.245.123; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14305 Date: 2010-09-28T15:04:28-07:00 List-Id: On 28 Wrz, 17:15, Ludovic Brenta wrote: > Do you mean you don't like this one: > > =A0 =A0procedure Start > =A0 =A0 =A0(Web_Server : in out HTTP; > =A0 =A0 =A0 Dispatcher : Dispatchers.Handler'Class; > =A0 =A0 =A0 Config =A0 =A0 : AWS.Config.Object); > > Personally it is the one I prefer. Why do you not like it? See my answer to Dmitry for code example. The above construct, by implicitly leaking references out of its execution, obstructs the scoping of object lifetime. > > 1. Object is an interface type for the callback that will be > > implemented by user. > > 2. Object_Access is a type that will be used for declaring and passing > > around callback references. I don't want everybody to define their own > > types for what is a common functionality. > > I don't think this functionality is that common; ideally the only > things you have to do with such references is record them in a > registry and then dereference them to call the callbacks. You wouldn't > "pass around" such references very often, I think. Especially if your > callbacks are allocated at elaboration and not dynamically on the > heap. That's right. Still, I need to express it somehow and I think that having an explicitly defined access type is a good practice. Unfortunately it does not seem to be compatible with the "limited with" feature. > I would probably use an instance of Ada.Containers.Indefinite_Vectors > or Indefinite_Doubly_Linked_Lists to hold an ordered list of class- > wide callback objects. Is that the language feature you were looking > for? Granted, such a container would duplicate the callback objects > ("functors") in memory; using access values would avoid that. Exactly, but copying is not the only problem. There are also dependencies. Note that my construct is not dependent on Ada.Containers and it allows the user to write programs without any use of dynamic memory. It is perfectly possible to create a callback object at the package level or local in a subprogram. > I would define the access type in the package that defines the > registry of callback objects, e.g. > > limited with Objects; > package Registry is > =A0 =A0type Callback is access all Objects.Object'Class; > =A0 =A0procedure Register (C : in Callback); > =A0 =A0procedure Call_All_Callbacks_In_Registration_Order; > end Registry; Interesting. I will have to meditate on this possibility. -- Maciej Sobczak * http://www.inspirel.com