Modulinos: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(Created Nim solution.)
Line 1,161: Line 1,161:
(println (format "Test: The meaning of life is %d" (SM:meaning-of-life)))
(println (format "Test: The meaning of life is %d" (SM:meaning-of-life)))
(exit)</syntaxhighlight>
(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}}==
=={{header|Objective-C}}==