* Kragen Javier Sitaker <kra...@canonical.org> [2012-03-27 13:15]: > There’s also the question of how to *write* a wider variety of > invocations than `for (foo: somegen) { ... }`. I mean, to do > Python’s: > > try: > x = somegen.next() > except StopIteration: > y() > else: > z(x) > > you could do: > > sometype x; > for (x: somegen) goto ok; > y(); > if (0) { > ok: > z(x); > } > > but that seems rather obscure! > > A reasonable, if not very C-like, syntax might be > > z(next(somegen) { y(); goto somewhere; }); > > That’s only reasonable because you almost always want to handle the > end of an iterator using some kind of nonlocal transfer of control, > even if only a `break;`.
A reasonable and more C-like syntax seems very easy to devise by simply crossing `if` with iterator-`for`: next (x: somegen) { z(x) } else { y() } For the hell of it it might be even possible to use `if` itself, much like you have made `for` carry several different semantics. OTOH over in Perl 6-land they are discovering that it is better to mostly not overload things (so `for` only does list iteration and there is a new `loop (;;)` keyword for C-style iteration, and likewise many other things that had multiple duties in Perl 5 have become multiple separate things). So maybe it is actually better for both looping and single-stepping iteration to to have dedicated keywords separate from `for` and `if`. Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/> -- To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-discuss