* David Green <david.gr...@telus.net> [2008-12-16 18:30]:
> So what if we had "LOOP $n {}" that executed on the nth
> iteration?

Ugh. Please no. Now you suddenly have this odd new corner of the
language with all its very own semantics and you have to figure
out how to make it orthogonal enough and when it’s evaluated and
a million other details in order to make it actually useful, and
in the end you have a bigger language with yet another mechanism
bolted on.

The way Template Toolkit solves this is far better: the loop body
gets access to an iterator object which can be queried for the
count of iterations so far and whether this is the first or last
iteration.

Thay would result in the following:

    repeat {
        @stuff = grep { !.valid }, @stuff };
        ENTER {
            next if $????.first;
            .do_something( ++$i ) for @stuff;
        }
    } while @stuff;

And now suddenly you don’t need to spec out a complicated single-
purpose mechanism, and you can still realise far more powerful
control flows than the single-purpose mechanism could ever hope
to provide. Not only that, but you get access to the information
as data in the program so you can do many more things with it
compared to if it were locked up in the invocation semantics of a
closure trait.

`FIRST` and `LAST` are justifiable regardless of what other
mechanisms are available simply because they’re things you want
so frequently. `LOOP n` is just overgeneralisation. Thumbs down.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to