comp.lang.ada
 help / color / mirror / Atom feed
* Possible for Ada 2020: "Cursors" for Arrays
@ 2013-06-04  1:09 Shark8
  2013-06-04  6:19 ` Niklas Holsti
  2013-06-04 20:47 ` Adam Beneschan
  0 siblings, 2 replies; 6+ messages in thread
From: Shark8 @ 2013-06-04  1:09 UTC (permalink / 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?


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

end of thread, other threads:[~2013-06-06  8:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-04  1:09 Possible for Ada 2020: "Cursors" for Arrays Shark8
2013-06-04  6:19 ` 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

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