On Tue, 31 Mar 2009, Jon Lang wrote:
> 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

I choose #3.

Reality can only take one path through a conditional; which one depends
on the one/any/all/none binding of the junction.

Once you've passed the conditional, you have:

        one -> single matching value (no longer a junction)
        any -> filtered list
        all -> original junction
        none -> empty (*1)

The "threading" is an implementation detail; the important thing is a
junction is collection of values and a smart way of rewriting
expressions that contain them, with special treatment for comparison
operators (or indeed anything that forces Boolean content):

        $x CMP all($y,$z)       $x CMP $y && $x CMP $z
        $x CMP one($y,$z)       $x CMP $y ^^ $x CMP $z  (*2)
        $x CMP none($y,$z)      all($x !CMP $y, $x !CMP $z)
        $x CMP any($y,$z)       $x !CMP none($y, $x)

        $x OP all($y,$z)        all( $x OP $y, $x OP $z)
        $x OP any($y,$z)        any( $x OP $y, $x OP $z)
        $x OP one($y,$z)        one( $x OP $y, $x OP $z)
        $x OP none($y,$z)       none($x OP $y, $x OP $z)

-Martin

(*1: An argument could be made that "none" should leave the junction alone,
the same as "all".)

(*2: I would like to suggest that the semantics of "one" be changed to mean
"pick one" (randomly) rather than "exactly one". In this respect it
would be the same as "any" except it wouldn't have the overhead of
filtering *every* match, just at least one.)

Reply via email to