September 15, 2003 foreach improvement suggestion | ||||
|---|---|---|---|---|
| ||||
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
| ||||
September 15, 2003 Re: foreach improvement suggestion | ||||
|---|---|---|---|---|
| ||||
Posted in reply to pts+d | <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. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply