Modulinos: Difference between revisions
m
→{{header|Wren}}: Minor tidy
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Minor tidy) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 423:
(load "scriptedmain.el" nil t)
(message "Test: The meaning of life is %d" (meaning-of-life)))</syntaxhighlight>
=={{header|EMal}}==
{{trans|Wren}}
<syntaxhighlight lang="emal">
^|We have created a module named ModulinosPart.emal.
|^
in Org:RosettaCode
type ModulinosPart
fun meaningOfLife = int by block do return 42 end
fun main = void by block do writeLine("The meaning of life is " + meaningOfLife() + ".") end
if Runtime.direct() do main() end
</syntaxhighlight>
{{out}}
<pre>
emal.exe Org\RosettaCode\ModulinosPart.emal
The meaning of life is 42.
</pre>
<syntaxhighlight lang="emal">
^|Then we create a new module named Modulinos.emal,
|this imports the previous module.
|^
in Org:RosettaCode
load :ModulinosPart
type Modulinos
fun main = int by List args
writeLine("Who says the meaning of life is " + ModulinosPart.meaningOfLife() + "?")
return 0
end
exit main(Runtime.args)
</syntaxhighlight>
{{out}}
<pre>
emal.exe Org\RosettaCode\Modulinos.emal
Who says the meaning of life is 42?
</pre>
=={{header|Erlang}}==
Line 1,161 ⟶ 1,196:
(println (format "Test: The meaning of life is %d" (SM:meaning-of-life)))
(exit)</syntaxhighlight>
=={{header|Nim}}==
Nim provides the predicate <code>isMainModule</code> to use with conditional compilation. Here is an example:
<syntaxhighlight lang="Nim">proc p*() =
## Some exported procedure.
echo "Executing procedure"
# Some code to execute to initialize the module.
echo "Initializing the module"
when isMainModule:
# Some code to execute if the module is run directly, for instance code to test the module.
echo "Running tests"
</syntaxhighlight>
{{out}}
When run directly, the result of execution is:
<pre>Initializing the module
Running tests
</pre>
If we call “p” from another module, we get:
<pre>Initializing the module
Executing procedure
</pre>
=={{header|Objective-C}}==
Line 1,959 ⟶ 2,019:
First we create a module for our modulino:
<syntaxhighlight lang="
var MeaningOfLife = Fn.new { 42 }
Line 1,969 ⟶ 2,029:
// Check if it's being used as a library or not.
import "os" for Process
if (Process.allArguments[1] == "
main.call()
}</syntaxhighlight>
Line 1,980 ⟶ 2,040:
Next we create another module which imports the modulino:
<syntaxhighlight lang="
import "./
var main = Fn.new {
|