Search code examples
operatorsuser-defined-functionsread-eval-print-loopraku

Why don't new operator definitions persist in the Perl 6 REPL?


I was having issues experimenting with defining operators on the Perl 6 REPL, and noticed that they do work, but only when used on the same line as they are defined. Why is this the case?

> sub postfix:<!>(Int $x where { $x >= 0 }) { [*] 1..$x }; 6!;
720
> 6!;
===SORRY!=== Error while compiling:
Negation metaoperator not followed by valid infix
------> 6!⏏;
    expecting any of:
        infix
        infix stopper

Solution

  • It's a bug.

    See bug reports Perl6 REPL forgets the definition of ... and REPL issue defining new operator... for more details.