Discussion:
higher-order programming and concurrency in low-level languages
Aristotle Pagaltzis
2012-05-19 05:02:17 UTC
Permalink
There’s also the question of how to *write* a wider variety of
invocations than `for (foo: somegen) { ... }`. I mean, to do
x = somegen.next()
y()
z(x)
sometype x;
for (x: somegen) goto ok;
y();
if (0) {
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.
Loading...