I've been having some second thoughts concerning this.  Here's where I
stand on it now:

In Perl 6, you have the following "decision points", where code may or
may not be executed depending on a condition:
if/unless/while/until/loop/when statements; if/unless/while/until
statement modifiers; short-circuit operators; the trinary conditional
operator.  When you apply a junction to a decision point, only one of
the possible paths will be taken; and the any/all/one/none nature of
the junction will determine which one.  (Without this, there would be
no reason to have a distinction between any/all/one/none.)  However, I
stand by my proposal that after passing one of these decision points,
and until you get back to code that would have been reached regardless
of the decision point, every junction that was involved in the
decision point should be limited such that it acts as if only those
possibilities within it that would have passed the decision point
exist.

With "unless", "while", "until", and "loop", the associated block is
the conditional block where the junction gets filtered.  With "if",
the main block likewise filters the junctions; but the "else" block
also provides junction filtering, but in a way that's complementary to
what the main block does.

With short-circuit operators, the RHS counts as a "block" that
provides junction filtering based on what it would take for the LHS to
avoid tripping the short-circuit behavior.  Similarly, "?? ::" treats
the expression following the ?? as a junction-filtering "block" and
the expression following the :: as a complementary junction-filtering
"block", in direct analogy to "if/else", above.

Finally, there's the "when" statement: as with "if", etc., the block
that follows the when statement filters junctions according to the
match criterion.  However, "when" is a bit more complicated in terms
of getting it to DWIM w.r.t. junctions.  Because of the way that
"when" works conceptually, I'd recommend that for the rest of the
block containing the "when" statement, it should provide the same sort
of complementary filtering that an "else" block does for an "if"
statement.  That is:

    given $x {
        when $a { ... }
        when $b { ... }
        when *
    }

...should not be thought of as being equivalent to:

    given $x {
        if $_ ~~ $a { ...; break }
        if $_ ~~ $b { ...; break }
        if $_ ~~ * {...; break }
    }

...but rather:

    given $x {
        if $_ ~~ $a { ... }
        else {
            if $_ ~~ $b { ... }
            else {
                if $_ ~~ * { ... }
            }
        }
    }

--

Another issue: what happens if conditional code mutates a junction
that it filtered?  For example:

    $x = any (-5 .. 5);
    if $x > 0 { $x++ };

At this point, which of the following does $x equal?

    any(-4 .. 6) # the original junction gets mutated
    any(-5 .. 0, 2 .. 6) # the filtered part of the original junction
gets mutated; the rest is untouched
    any(2 .. 6) # the filtered part of the original junction gets
mutated; the rest is lost

--
Jonathan "Dataweaver" Lang

-- 
Jonathan "Dataweaver" Lang

Reply via email to