5

I'm trying to make ¬ a logical negation operator.

¬ True;

multi sub prefix:<¬> ($n) {
        return not $n;
}

When I run the above program, it returns this error:

$ perl6 test.pl6  
===SORRY!=== Error while compiling /home/devXYZ/test.pl6 Bogus statement at /home/devXYZ/test.pl6:1
------> <BOL>⏏¬ True;
expecting any of:
    prefix
    term

Does anyone know what the cause might be?

Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
user6189164
  • 667
  • 3
  • 7

1 Answers1

7

The declaration of the new operator must appear before its usage. Changing the program to:

multi sub prefix:<¬> ($n) {
    return not $n;
}
say ¬ True;

Makes it work fine.

Perl 6 has strict one-pass parsing rules. Therefore, order matters with anything that influences the language being parsed - such as by introducing a type or a new operator.

Jonathan Worthington
  • 29,104
  • 2
  • 97
  • 136