On 10/13/22 9:19 PM, Ralph Mellor wrote:
On Fri, Oct 14, 2022 at 12:37 AM Joseph Polanik <jpola...@charter.net> wrote:
I am trying to define '!' as the factorial operator. The following works
in a .raku script file:

    sub postfix:<!> ($n) is export {
      when $n == 0 {return 1}
      default {$n * ($n - 1)!}
    }

However when I tried to move this sub to a .rakumod file,
it produces an error: Negation metaoperator not followed
by valid infix.
That's because Raku isn't picking up your `sub`.

I don't know why. It works for me. (v2022.02)

Are you sure you're `use`ing it correctly and the `sub`
has the `is export`?

Yes, the sub that defines the factorial operator is marked with 'is export' and the script that invokes my module (SequenceHelper) has a 'use' statement.

The script is able to invoke other methods marked 'is export'; for example, the simple ver() and a method that generates an integer sequence:

  sub genSeq_IndexOps($limit, $f) is export {
    my @a = ();
    for (0...^$limit) -> $n {
      @a.push($f($n));
    }
    return @a;
  }

So the module is being found and used. It seems as if certain methods aren't being found.

I am not convinced that the problem I'm having is unrelated to the issue raised concerning the REPL. When I use the REPL, the results are the same.

[0] > use SequenceHelper;
Nil
[1] > say ver();
v0.0.1
[1] > say 4!;
===SORRY!=== Error while compiling:
Negation metaoperator not followed by valid infix
[1] > put genSeq_IndexOps(15, -> $x {3**$x + 5**$x + 6**$x});
3 14 70 368 2002 11144 63010 360248 2076802 12050504 70290850 411802328 2421454402 14282991464 84472462690

Regards,

Joe

Reply via email to