Modulinos: Difference between revisions

Created Nim solution.
m (syntax highlighting fixup automation)
(Created Nim solution.)
Line 1,161:
(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}}==
256

edits