πŸ“˜ Junction operators |, &, and ^ in Perl 6

πŸ“˜ Junction operators |, &, and ^ in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


|, &, and ^ create the so-called junctions (formerly known in Perl 6 as quantum superpositions). These objects can be used where a scalar is used but behave differently; unlike the scalars, the junctions have multiple values at the same moment in time.

The |, &, and ^ operators create, respectively, the junctions of the any, all, and one types.

# The value of 4 is one of the listed options
say "ok" if 4 == 1|2|3|4|5;Β Β 

# There is no 4 in the list
say "ok" if 4 != 1 & 2 & 3 & 5; Β 

# 4 repeats twice, thus it is not unique
say "ok" unless 4 == 1 ^ 2 ^ 2 ^ 4 ^ 4 ^ 5;

One thought on “πŸ“˜ Junction operators |, &, and ^ in Perl 6”

  1. Thanks for this great series!

    Is this comment correct?
    # There is no 4 in the list
    say “ok” if 4 != 1 & 2 & 3 & 5; # ok
    Consider:
    say “ok” if 4 != 1 & 2 & 3 & 4 & 5; # ok
    say “ok” if 4 == 4 & 4 & 4; # ok
    say “ok” if 4 == 4 & 4 & 4 & 3; # ()

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code