

Python's if __name__=="__main__": main() in other languages - mcandre

This behavior is very hard to Google. For now, I'm calling it "scripted main" and I'm cataloging it for several programming languages.<p>Ruby: if __FILE__ == $0 then main end<p>Perl: unless(caller) { main; }<p>...<p>https://github.com/mcandre/scriptedmain<p>Does anyone know the syntax for this in GNU Smalltalk?
======
damncabbage
PHP: if (realpath($argv[0]) == __FILE__) main();

(Presuming you've gone and defined the main() function somewhere. No module
conventions like with Python here.)

------
booz
for node.js

if (!module.parent) { // your main here }

~~~
mcandre
Thanks! That one's at
[https://github.com/mcandre/scriptedmain/blob/master/scripted...](https://github.com/mcandre/scriptedmain/blob/master/scriptedmain.js)
and <https://github.com/mcandre/scriptedmain/blob/master/test.js>

