comp.lang.ada
 help / color / mirror / Atom feed
* Generalized Loop Iteration and User-Defined Indexing with more than two parameters.
@ 2020-11-01 18:41 Blady
  2020-11-03 11:05 ` Stephen Leake
  0 siblings, 1 reply; 7+ messages in thread
From: Blady @ 2020-11-01 18:41 UTC (permalink / raw)


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);
      9.       function Make (Value : String) return UXString;
     10.       function Length (Self : UXString) return Natural;
     11.       function Get (Self : UXString; Index : Positive; 
Substitute : in Character) return Character;
     12.       function First (Self : UXString) return Positive is (1);
     13.       function Next (Self : UXString; Index : Positive) return 
Positive is (Index + 1);
     14.       function Has_Element (Self : UXString; Index : Positive) 
return Boolean is (Index <= Self.Length);

The Get constant indexing function has more than two parameters.
GNAT 2020 compilation is ok with the "for ... in ... loop" form:

     47.    for I in S1 loop
     48.       C := S3 (I, '@');
     49.       Put_Line (Character'pos (C)'img);
     50.    end loop;

  but not with the "for ... of ... loop" form (S2 and S3 loops):

     51.    for CC of S2 loop
     52.       C := CC;
     53.       F := CC = 'h';
     54.       Put_Line (Character'pos (C)'img & F'img);
     55.    end loop;
test_uxstrings_4.adb:51:17: error: missing argument for parameter 
"Substitute" in call to "Get" declared at line 11

     56.    for CC of S3 ('@') loop
     57.       C := CC;
     58.       F := CC = 'h';
     59.       Put_Line (Character'pos (C)'img & F'img);
     60.    end loop;
test_uxstrings_4.adb:56:14: error: container cannot be indexed with "A 
Character Type"

What is the correct usage?

Thanks, Pascal.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-11-10  1:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01 18:41 Generalized Loop Iteration and User-Defined Indexing with more than two parameters Blady
2020-11-03 11:05 ` Stephen Leake
2020-11-06 15:39   ` Blady
2020-11-07  0:58     ` Randy Brukardt
2020-11-07 17:46       ` Blady
2020-11-10  1:45         ` Randy Brukardt
2020-11-07 23:54       ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox