comp.lang.ada
 help / color / mirror / Atom feed
* Ada 2012 Iterators limitations & proposition
@ 2011-09-29 12:31 David Sauvage
  2011-09-30  1:44 ` Randy Brukardt
  0 siblings, 1 reply; 3+ messages in thread
From: David Sauvage @ 2011-09-29 12:31 UTC (permalink / raw)


Ada 2012 Iterators are very convenient by avoiding the user creating a
procedure that will be used via quote access to iterate.

The problem (may be a feature for some) is that, by hiding the
indexing it only gives the user an access to the Element of the
container/array, but no access to the corresponding key/index.

I think it would be interesting to be able to have a read-only access
the key/index. This is the only reason why I can't use this new
features every time I want it.

The only challenge is to declare the key and the element variable
instead of only the element, here is what I would propose to avoid any
language impact ;
Allow the user to specify 2 variables, separated by a comma.
If only one variable is present, it will be affected the element,
If two variables are present, the first is the key/index, the second
is the element.
The user could specify null instead of a variable name, if he only
wants the key/index for example.
Specifying null for key/index and element would not be legal.

      -- access only index/key
      for Key, null of Data.Processors loop
         Process (Key);
      end loop;

      -- access both index/key & element
      for Key, Element of Data.Processors loop
         Process (Key, Element);
      end loop;

      -- access to element only (2)
      for null, Element of Data.Processors loop
         Process (Element);
      end loop;

      -- access to element only (2), for compatibility
      for Element of Data.Processors loop
         Process (Element);
      end loop;


Cheers



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

end of thread, other threads:[~2011-09-30 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-29 12:31 Ada 2012 Iterators limitations & proposition David Sauvage
2011-09-30  1:44 ` Randy Brukardt
2011-09-30 15:39   ` David Sauvage

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