The cause of the problem may well need to be fixed for other reasons,
but re-purposing an almost universal operator like "!" ("not") sounds
like a thoroughly bad idea, the route to non-standard code.

If you must have a factorial operator, what's wrong with defining "Fact"?

On 10/14/22, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> I cannot reproduce:
>
> % cat lib/A.rakumod
> sub postfix:<!> ($n) is export {
>     when $n == 0 {return 1}
>     default {$n * ($n - 1)!}
> }
> % raku -e 'use lib "lib"; use A; say 42!'
> 1405006117752879898543142606244511569936384000000000
> % raku -v
> Welcome to Rakudo™ v2022.07-64-gce1af0fa0.
> Implementing the Raku® Programming Language v6.d.
> Built on MoarVM version 2022.07-16-g3ae8a31c1.
>
>> On 14 Oct 2022, at 05:30, Joseph Polanik <jpola...@charter.net> wrote:
>>
>>
>> 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