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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: how to use "in out" for the "self" parameter in a function in a protected object? Date: Sun, 17 Sep 2017 10:36:51 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 17 Sep 2017 08:36:51 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="79a5c3732aa83adf2361f374173849ea"; logging-data="20311"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l3tL3w+IXl9g77MWUxfLtj0D55v56gUU=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:BWR8G8/c9rnFcY0mdsTtRkJ1BjM= Xref: news.eternal-september.org comp.lang.ada:48163 Date: 2017-09-17T10:36:51+02:00 List-Id: On 09/17/2017 12:40 AM, Frank Buss wrote: > > What's the rationale for this behavior and where can I find the definition, that > it is not allowed? Doesn't look useful to me, because I can do this with a > procedure. In fact now I have written a procedure with an "out" parameter and it > works. But it is annoying to declare an extra temporary variable for it when I > call it. Would be nice, if I could do this with a function. Modifying the state of a protected object requires exclusive access to it (a lock of some sort). Simply reading the state does not require a lock, and multiple reads may proceed in parallel. The definition of POs in 1995 used protected functions for non-exclusive, read-only access, and protected procedures and entries for exclusive write access. One can debate whether this was the best decision, but that's the way POs are defined. One way to get a function that modifies the state is to have a function that calls a procedure of the PO and returns the value it obtains. Taken to its logical conclusion, the PO can be hidden in a pkg body and accessed through public subprograms. -- Jeff Carter "My little plum, I am like Robin Hood. I take from the rich, and I give to the poor. ... Us poor." Poppy 96