www.digitalmars.com         C & C++   DMDScript  

D - foreach improvement suggestion

reply pts+d math.bme.hu writes:
Dear All,

I suggest an improvement over foreach on objects:

Now works: foreach (item; container) { ... }

Should be added: foreach (item; container_obj.apply1) { ... }
foreach (item; container_obj.apply2) { ... }

This way we could have iterators which iterate over only parts of the container:

-- hash.keys
-- hash.values
-- hash.pairs
-- file.lines
-- file.chars

I'd also like to suggest a syntax sugar: for and foreach could be synonyms, just
as in Perl.

pts
Sep 15 2003
parent "Walter" <walter digitalmars.com> writes:
<pts+d math.bme.hu> wrote in message news:bk4nbe$2dtt$1 digitaldaemon.com...
 Dear All,

 I suggest an improvement over foreach on objects:

 Now works: foreach (item; container) { ... }

 Should be added: foreach (item; container_obj.apply1) { ... }
 foreach (item; container_obj.apply2) { ... }

 This way we could have iterators which iterate over only parts of the
container:
 -- hash.keys
 -- hash.values
 -- hash.pairs
 -- file.lines
 -- file.chars
I understand the need for this, and I think I have a way to make it work. Stay tuned!
 I'd also like to suggest a syntax sugar: for and foreach could be
synonyms, just
 as in Perl.
It makes it easier to parse them if they are separate.
Sep 15 2003