From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.pBWEO6hi52oGFheO/GY5ag.user.gioia.aioe.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Generalized Loop Iteration and User-Defined Indexing with more than two parameters. Date: Tue, 03 Nov 2020 03:05:50 -0800 Organization: Aioe.org NNTP Server Message-ID: <86361qwvht.fsf@stephe-leake.org> References: NNTP-Posting-Host: pBWEO6hi52oGFheO/GY5ag.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) Cancel-Lock: sha1:xr52zAkKaAi5/V1tmpeU03vKVik= X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:60541 List-Id: Blady writes: > Hello, > > Let's take the following container with constant indexing for iteration: > > 6. type UXString is tagged private with > 7. Constant_Indexing => Get, > 8. Iterable => (First => First, Next => Next, > Has_Element => Has_Element, Element => Get); > 11. function Get (Self : UXString; Index : Positive; > Substitute : in Character) return Character; Hmm. Aspect "Iterable" is not defined by Ada. It is defined by GNAT. The gnat reference manual says: * The value of `Element' is a primitive operation of the container type that takes both a container and a cursor and yields an `Element_Type', which must be a type declared in the container package or visible from it. For example: function Get_Element (Cont : Container; Position : Cursor) return Element_Type; So it should have complained that your "Element => Get" is illegal. > What is the correct usage? An iterator 'Element' function can take only two parameters; the same is true for standard Ada generalized iterators. A Constant_Indexing function can take more than two parameters, but you can only use it by indexing a container object directly (see LRM 4.1.6), A : UXString; for Position in A.First .. A.Last loop Foo := A (Position, Substitute => 'C'); ... -- -- Stephe