From: Shark8 <onewingedshark@gmail.com>
Subject: Possible for Ada 2020: "Cursors" for Arrays
Date: Mon, 3 Jun 2013 18:09:01 -0700 (PDT)
Date: 2013-06-03T18:09:01-07:00 [thread overview]
Message-ID: <55016aa4-4d69-4fd9-a2c9-a7eb7d3b00c5@googlegroups.com> (raw)
In a few threads a few people have expressed a desire to be able to initialize Arrays based on some formula usually including the indices. In order to do this we need some sort of "cursor"-type/attribute.
So, let us propose a cursor-attribute so that some array type, T1, defined as
type T1 is Array( 1..10 ) of Integer;
could have a variable initialized as follows:
V1 : T1:= (others => T1'Cursor'Index)
resulting in V1 getting (1,2,3,4,5,6,7,8,9,10);
This doesn't scale to unconstrained arrays, however because given
type T2 is Array( Positive Range <>) of Integer
V2 : T2 := (others => others => T1'Cursor'Index)
becomes ambiguous/indeterminate [lacking any constraints to determine the correct size] -- this could be ameliorated by requiring explicit bounds and throwing a compiler error.
Taking a page from the 'Length attribute we could make the attribute take an optional parameter indicating which of the indices we are referring to.
-- completely forced example.
Type CBT is Array(1..8,'A'..'H') of Piece;
-- Transforms (1,A) to 1, (1,B) to 9, [...], (8,H) to 64
Chess_Board_Transform : CBT :=
(others => 8*(Character'Pos(CBT'Cursor(2))-Character'Pos'A') + CBT'Cursor(1) );
Note that because we know the types for the indices we should be able to use the cursor as that type for that index... This would also be a good place for implementation of a 'Type attribute, as matching the 'cursor' to that particular index would entail interrogating the previously known definition for the proper type anyway.
My question: does this look reasonable, or is it just superfluous?
next reply other threads:[~2013-06-04 1:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 1:09 Shark8 [this message]
2013-06-04 6:19 ` Possible for Ada 2020: "Cursors" for Arrays Niklas Holsti
2013-06-04 14:18 ` Shark8
2013-06-04 19:27 ` Niklas Holsti
2013-06-04 20:47 ` Adam Beneschan
2013-06-06 8:58 ` Jacob Sparre Andersen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox