Modulinos: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: now builtin)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1,274: Line 1,274:
print "Life means " . Life::meaning_of_life . ".\n";
print "Life means " . Life::meaning_of_life . ".\n";
print "Death means invisible scary skeletons.\n";</lang>
print "Death means invisible scary skeletons.\n";</lang>
=={{header|Perl 6}}==
Perl 6 automatically calls MAIN on direct invocation, but this may be a multi dispatch, so a library may have multiple "scripted mains".
<lang perl6>class LUE {
has $.answer = 42;
}

multi MAIN ('test') {
say "ok" if LUE.new.answer == 42;
}

multi MAIN ('methods') {
say ~LUE.^methods;
}</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,363: Line 1,350:
print("Life means %s." % meaning_of_life())
print("Life means %s." % meaning_of_life())
print("Death means invisible scary skeletons.")</lang>
print("Death means invisible scary skeletons.")</lang>

=={{header|R}}==
=={{header|R}}==
A way to check if code is running at "top level" is to check <code>length(sys.frames())</code>. This value will be zero for a file being run with <code>Rscript</code>, the <code>--file=</code> argument, or at the command line, and will be greater than 0 in all other conditions (such as package loading or code being sourced from another file.)
A way to check if code is running at "top level" is to check <code>length(sys.frames())</code>. This value will be zero for a file being run with <code>Rscript</code>, the <code>--file=</code> argument, or at the command line, and will be greater than 0 in all other conditions (such as package loading or code being sourced from another file.)
Line 1,410: Line 1,398:
(require "scriptedmain.rkt")
(require "scriptedmain.rkt")
(printf "Test: The meaning of life is ~a\n" (meaning-of-life)))</lang>
(printf "Test: The meaning of life is ~a\n" (meaning-of-life)))</lang>

=={{header|Raku}}==
(formerly Perl 6)
Perl 6 automatically calls MAIN on direct invocation, but this may be a multi dispatch, so a library may have multiple "scripted mains".
<lang perl6>class LUE {
has $.answer = 42;
}

multi MAIN ('test') {
say "ok" if LUE.new.answer == 42;
}

multi MAIN ('methods') {
say ~LUE.^methods;
}</lang>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,572: Line 1,575:
$ ./test
$ ./test
Test: The meaning of life is 42</lang>
Test: The meaning of life is 42</lang>

=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Scala}}
{{libheader|Scala}}
Line 1,726: Line 1,730:


Transcript show: 'Test: The meaning of life is ', ((ScriptedMain meaningOfLife) printString); cr.</lang>
Transcript show: 'Test: The meaning of life is ', ((ScriptedMain meaningOfLife) printString); cr.</lang>



=={{header|Swift}}==
=={{header|Swift}}==