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!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Getting the index for an element in mutually referencing containers Date: Sun, 12 Mar 2017 16:44:08 +0000 Organization: A noiseless patient Spider Message-ID: References: <86o9xa36oq.fsf@gaheris.avalon.lan> <86k27xpikd.fsf@gaheris.avalon.lan> <86wpbxneuz.fsf@gaheris.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="c479a7425843be0b5ee4598132ad9704"; logging-data="28474"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/J8I3CYEhiXxHA+Od2K0weWWFYOtPswYY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin) Cancel-Lock: sha1:atG8JdG2Q7IphamJgnJVLWdyMtQ= sha1:vUI1ACS3k0hc4yH+6eSotPOvA+M= Xref: news.eternal-september.org comp.lang.ada:27904 Date: 2017-03-12T16:44:08+00:00 List-Id: "Dmitry A. Kazakov" writes: > On 2017-03-12 12:30, Simon Wright wrote: >> "Dmitry A. Kazakov" writes: >> >>> On 2017-03-11 22:46, Simon Wright wrote: >> >>>> Basically, I (Simon, now) am having trouble thinking of an >>>> application where reference counting would be an appropriate >>>> solution. >>> >>> As I said, in practice it is all cases when you would have a >>> container of mutable elements. >> >> I had some trouble understanding your point the first time, and >> skipped over it (sorry). >> >> What's the opposite of "mutable"? constant? because, if so, why >> wouldn't I use Update_Element? > > Yes, But it is almost never element update. Usually what you want is > to call some mutable operations on the element. The language does not > offer user-defined by-reference or copy-out-copy-in methods to element > access. with Ada.Containers.Vectors; package Mutable_Elements is type Element is record Numeral : Integer := 0; end record; procedure Update (E : in out Element); package Element_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Element); Elements : Element_Vectors.Vector; end Mutable_Elements; package body Mutable_Elements is procedure Update (E : in out Element) is begin E.Numeral := E.Numeral + 1; end Update; end Mutable_Elements; with Ada.Text_IO; with Mutable_Elements; procedure Mutable_Elements_Test is use Mutable_Elements; begin for J in 1 .. 5 loop Elements.Append (Element'(Numeral => J)); end loop; Elements (4).Numeral := Elements (4).Numeral + 1; Ada.Text_IO.Put_Line ("Elements (4).Numeral: " & Elements (4).Numeral'Img); Update (Elements (4)); Ada.Text_IO.Put_Line ("Elements (4).Numeral: " & Elements (4).Numeral'Img); end Mutable_Elements_Test; $ ./mutable_elements_test Elements (4).Numeral: 5 Elements (4).Numeral: 6