in reply to Re^6: "when" and replacements
in thread "when" and replacements

Your implying that last (which doesn't look odd) couldn't be used because next is possible.
So, then the rule would be "when using when, there is an implied last when used inside a given, but there's an implied next when used inside a for"?

Not sure if that's an improvement.

consequently full orthogonality would imply allowing multiple args in given(LIST)
Uhm, do realize that given(EXPR) evaluates EXPR in scalar context, while for(EXPR) evaluates in EXPR in list context. As such, given(LIST) isn't meaningful. Changing the context means that you break given(@ARRAY).

If you want given to behave exactly as for, write for. I rather have given to be different from for, then given to be another alias for for/foreach.

Replies are listed 'Best First'.
Re^8: "when" and replacements
by LanX (Saint) on May 07, 2011 at 14:28 UTC
    > So, then the rule would be "when using when, there is an implied last when used inside a given, but there's an implied next when used inside a for"?

    No it's always an implied "next", for one-time-loops "next" and "last" just mean the same thing.

    BTW: perlsyn already has such a complicated rule:

    Every "when" block is implicitly ended with a "break".
    and

    Instead of using "given()", you can use a "foreach()" loop. ... On exit from the "when" block, there is an implicit "next".

    > I rather have given to be different from for, then given to be another alias for for/foreach.

    My intention was to have a "foreach" variant without automatic aliasing of the variable...

    > Changing the context means that you break given(@ARRAY).

    Yep, it's too late to change "given" now ...

    I still prefer avoiding "given/when" at least until I'm smart enough for smart match.

    And passing lists of arrays is no problem with \(...)

    DB<100> @a=1..3 DB<101> @b=4..6 DB<102> for (\(@a,@b)) {print} ARRAY(0xa3dcd78)ARRAY(0xa3dcc48) DB<103> for (\(@a,@b)) {print @$_} 123456

    while "given" relies on magic:

    So "given(@foo)" is the same as "given(\@foo)"

    Cheers Rolf