Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

invent some syntax

20 views
Skip to first unread message

Roedy Green

unread,
Sep 1, 2012, 8:16:21 PM9/1/12
to
If Java were to be extended so you could call Iterator.remove inside a
for:each, what sort of syntax might you use?
--
Roedy Green Canadian Mind Products http://mindprod.com
A new scientific truth does not triumph by convincing its opponents and making them see the light,
but rather because its opponents eventually die, and a new generation grows up that is familiar with it.
~ Max Planck 1858-04-23 1947-10-04


Boudewijn Dijkstra

unread,
Sep 11, 2012, 3:19:49 PM9/11/12
to
Op Sun, 02 Sep 2012 02:16:21 +0200 schreef Roedy Green
<see_w...@mindprod.com.invalid>:
> If Java were to be extended so you could call Iterator.remove inside a
> for:each, what sort of syntax might you use?

First let's establish that any such new syntax would not apply when
iterating over an array (cause a compile-time error).

A new keyword "remove" could be introduced:

for (E e : c)
remove;

In case of nesting, I guess this keyword should be defined as to remove
the current item from the Iterator belonging to the most deeply nested
for:each block in the current scope.

for (V v : foo)
for (K k : v.bar())
remove; // removes k, not v

Another extended syntax would be needed if you want to be able to
explicitly select an iterator:

for (V v : foo : Iterator<V> vi)
for (K k : v.bar())
if (k.isBaz(v)) {
vi.remove();
break;
}



--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/
0 new messages