In Perl 6, a superposition is a simultaneous combination of various elements, generalized from quantum mechanics. For simplicity, Perl does not entangle itself with the details of entanglement.

Superpositions are constructed through the use of the any and all operators. These have infix equivalents: | and & (formerly bitwise or and and). These operators, incidentally, should be read "or" and "and."

Superpositions are a way to declaratively state what would previously have only been possible procedurally. So, instead of:

    if $a == 1 || $a == 2 || $a == 3 { ... }

You could write:

    if $a == 1 | 2 | 3 { ... }
# (which is)
    if $a == any(1, 2, 3) { ... }

Following the dreams of many early programmers. Of course, these statements really return a superposition of boolean: if $a was 2, then the former statement would be any(false, true, false). But a disjunctive superposition evaluates true if any of its arguments are true. Conversely, a conjunctive superposition evaluates true only if all of its arguments are true. This ends up DWIMming.

You can combine superpositions on both sides of a comparison:

    if 3 < 2 | 4 | 6 { ... }  # True
    if 3 < 2 & 4 & 6 { ... }  # False
    if 3 & 4 < 5     { ... }  # True
    if 3 & 5 < 5     { ... }  # False
    if 2 | 3 < 3 & 7 { ... }  # True
    if 6 & 7 < 4 | 6 { ... }  # False

Scalar arithmetic on a superposition works just like that on a vector:

    2 * any(1, 2, 3) == any(2, 4, 6)

You can combine superpositions:

    if all(1,2,3)*any(5,6) < 21 { print "No Alchohol!\n"}
# (Equivalent to:)
    if any(all(5,10,15),all(6,12,18)) < 21 { ... }
# (Or:)
    if all(any(5,6),any(10,12),any(15,18)) < 21 { ... }

As you can see, they are stored and evaluated recursively. This is very handy.

Perl 6 will allow extraction of the eigenstates of a superposition, with the states function. This along with the isa function allows you to decompose a superposition completely (despite the theoretical impossibility from quantum mechanics):

    sub printsuper($sup) {
        given $sup {
            when Superposition::Conjunction {
                print "all(";
                printsuper($_) for states;
                print ")";
            }
            when Superposition::Disjunction {
                print "any(";
                printsuper($_) for states;
                print ")";
            }
            default {
                print;
            }
        }
        print ",";
    }

(given..when is the Perl6 equivalent of C's switch..case. The exact class names that all and any produce have yet to be decided)

Note that the return value of a boolean comparison is another superposition of all the states that matched:

    (3 | 4 | 5 < 4)  == 3
    (3 | 4 | 5 < 5)  == 3 | 4
    (3 & 4 & 5 < 6)  == 3 & 4 & 5

This turns out to be a lot more useful than a bare boolean.

It is now decided that these will be called junctions, where all is a conjunction, and any is a disjunction. This was decided to help beginners grok the concept better, with a more familiar word.