Executable library: Difference between revisions
m
→{{header|Wren}}: Minor tidy
m (→{{header|Sidef}}: update) |
m (→{{header|Wren}}: Minor tidy) |
||
Line 2,236:
The strategy here is check whether the main module is the same as the library module and to treat is as executable if it is but as a library otherwise.
<syntaxhighlight lang="
var Hailstone = Fn.new { |n|
Line 2,272:
// Check if it's being used as a library or not.
import "os" for Process
if (Process.allArguments[1] == "
libMain_.call()
}</syntaxhighlight>
Line 2,279:
If we run this directly, we get the expected output:
<pre>
$ wren
For the Hailstone sequence starting with n = 27:
Line 2,292:
If we now create a second module which imports the above and calls its Hailstone function:
<syntaxhighlight lang="
import "./
var freq = {}
Line 2,316:
We can now run this to check that the executable code in hailstone.wren has been suppressed, giving us:
<pre>
$ wren
The Hailstone length returned most is 72, which occurs 1467 times.
|