Modulinos: Difference between revisions

Added Wren
(Added Wren)
Line 1,876:
echo "Test: The meaning of life is $?"
</lang>
 
=={{header|Wren}}==
As far as Wren is concerned, a modulino and an executable library seem to be different names for the same thing. This therefore uses the same technique as the [[Executable_library#Wren]] task to create a simple modulino.
 
Note that Wren doesn't need or normally use a ''main()'' function to start a script, though we use one here to make the example clearer.
 
First we create a module for our modulino:
<lang ecmascript>/* modulino.wren */
 
var MeaningOfLife = Fn.new { 42 }
 
var main = Fn.new {
System.print("The meaning of life is %(MeaningOfLife.call()).")
}
 
// Check if it's being used as a library or not.
import "os" for Process
if (Process.allArguments[1] == "modulino.wren") { // if true, not a library
main.call()
}</lang>
 
and run it to make sure it works OK when run directly:
{{output}}
<pre>
The meaning of life is 42.
</pre>
 
Next we create another module which imports the modulino:
<lang ecmascript>/* modulino_main.wren */
 
import "/modulino" for MeaningOfLife
 
var main = Fn.new {
System.print("Who says the meaning of life is %(MeaningOfLife.call())?")
}
 
main.call()</lang>
 
and run this to make sure the modulino's ''main()'' function doesn't run:
{{output}}
<pre>
Who says the meaning of life is 42?
</pre>
 
=={{header|ZX Spectrum Basic}}==
9,476

edits