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,c08a7609345f4e5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!postnews.google.com!j24g2000yqa.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Limited use for limited with? Date: Tue, 28 Sep 2010 08:15:46 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7acf7226-e945-4683-b8a6-ca66f07fe7a1@j24g2000yqa.googlegroups.com> References: <853314bc-0f79-435f-86a5-d7bcdd610731@c10g2000yqh.googlegroups.com> <36e886fa-b272-461f-bf86-a6b18366b64f@i5g2000yqe.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1285686946 26392 127.0.0.1 (28 Sep 2010 15:15:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 28 Sep 2010 15:15:46 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j24g2000yqa.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14294 Date: 2010-09-28T08:15:46-07:00 List-Id: Maciej Sobczak wrote on comp.lang.ada: > So let's say that I already did the thinking and the most prevalent > use case for access types is callback registration. > > Think about AWS dispatchers for the closest analogy. > In fact, the AWS.Server.Start procedure has a version that takes the > callback by access. It is an access to function, but I need it to be > object-oriented. OK, functors then (I believe this word is C++ jargon). > Hiding the use of access values behind the scenes (by virtue of tagged > types being always passed by reference) would obstruct the code > without clear benefit. This is what AWS does in its other versions of > Start, but I don't like it. Do you mean you don't like this one: procedure Start (Web_Server : in out HTTP; Dispatcher : Dispatchers.Handler'Class; Config : AWS.Config.Object); Personally it is the one I prefer. Why do you not like it? > I want to express this: > > 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. > I totally agree that in Ada the pressure for using access values is > much smaller than in C++, but object registration (in a map, perhaps) > is not addressed by any other language 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. > Should I drop the Object_Access type altogether and mess with locally- > defined access types in other parts of the code? I would define the access type in the package that defines the registry of callback objects, e.g. limited with Objects; package Registry is type Callback is access all Objects.Object'Class; procedure Register (C : in Callback); procedure Call_All_Callbacks_In_Registration_Order; end Registry; -- Ludovic Brenta.