Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Identifier) terms vs. constants vs. null signature routines

Tags:

raku

Identifier terms are defined in the documentation alongside constants, with pretty much the same use case, although terms compute their value in run time while constants get it in compile time. Potentially, that could make terms use global variables, but that's action at a distance and ugly, so I guess that's not their use case. OTOH, they could be simply routines with null signature:

sub term:<þor> { "Is mighty" }
sub Þor { "Is mighty" }

say þor, Þor;

But you can already define routines with null signature. You can sabe, however, the error when you write:

say Þor ~ Þor;

Which would produce a many positionals passed; expected 0 arguments but got 1, unlike the term. That seems however a bit farfetched and you can save the trouble by just adding () at the end.

Another possible use case is defying the rules of normal identifiers

sub term:<✔> { True }
say ✔; # True

Are there any other use cases I have missed?

like image 792
jjmerelo Avatar asked Dec 13 '22 12:12

jjmerelo


1 Answers

Making zero-argument subs work as terms will break the possibility to post-declare subs, since finding a sub after having parsed usages of it would require re-parsing of earlier code (which the perl 6 language refuses to do, "one-pass parsing" and all that) if the sub takes no arguments.

like image 157
timotimo Avatar answered Mar 11 '23 21:03

timotimo