comp.lang.ada
 help / color / mirror / Atom feed
From: David Sauvage <david.sauvage@adalabs.com>
Subject: Ada 2012 Iterators limitations & proposition
Date: Thu, 29 Sep 2011 05:31:06 -0700 (PDT)
Date: 2011-09-29T05:31:06-07:00	[thread overview]
Message-ID: <37a42bc3-9efa-43b2-bf37-6198dc6ecf2b@db5g2000vbb.googlegroups.com> (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



             reply	other threads:[~2011-09-29 12:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-29 12:31 David Sauvage [this message]
2011-09-30  1:44 ` Ada 2012 Iterators limitations & proposition Randy Brukardt
2011-09-30 15:39   ` David Sauvage
replies disabled

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