On Fri Dec 28 11:54:18 2012, masak wrote:
> <Ayiko> r: for ^0 { FIRST say 'first'; LAST say 'last'; LEAVE say
> 'leave'; } # should this LAST be run?
> <p6eval> rakudo 930369: OUTPUT«last␤»
> <masak> Ayiko: S04 says "at loop termination time". even an empty loop
> could be said to terminate.
> <masak> r: for ^0 { my $a = 42; LAST { say $a } }
> <p6eval> rakudo 930369: OUTPUT«Any()␤»
> <Ayiko> but then FIRST runs at loop initialization time, shouldn't
> that run too then?
> <Ayiko> I understand there's a logic to it, it just happens to
> interfere with my current use case...
> <masak> Ayiko: I may be wrong.
> <masak> it also says "after any LEAVE", which would indicate that it
> is indeed tied to block entry/exit.
> <masak> I definitely agree that FIRST and LAST should behave similarly.

It's not so simple. We really want FIRST to run once we're in the
lexical scope of the loop, so any iteration parameters have been bound
and we can refer to them. However, we don't actually know until we've
invoked the block whether there will be another iteration, and thus
don't know whether to do LAST or not until after we've left the block.

While I can see the consistency you're after, I don't see a way to
(sanely) implement it.

Thoughts?

/jnthn

Reply via email to