Create a new operator

I am 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 could be causing?

+5
source share
1 answer

A new operator declaration must appear before using it. Program change to:

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

Makes it normal.

Perl 6 has strict one-pass parsing rules. Therefore, order matters in everything that affects the language that is being analyzed - for example, by introducing a type or a new operator.

+7
source

Source: https://habr.com/ru/post/1276058/


All Articles