Factor appears to have a main method like any C-based language:
#! /usr/bin/env factor -script
USE: io
IN: hello
: hello ( -- ) "Hello World!" print ;
MAIN: hello
But Factor does not execute the main function automatically; if you run ./hello.factor in a terminal, nothing happens because main isn't called.
Does anyone know if Factor has syntax like Python, so that hello is actually called on ./hello.py?
def hello():
print "Hello World!"
if __name__=="__main__":
main()
Factor will now execute a
mainfunction if one is specified. You'll still have to edit~/.factor-rcto add theINCLUDING/INmacros so that Factor will search for code in the current directory.~/.factor-rc:
scriptedmain.factor:
test.factor:
Example:
$ ./scriptedmain.factor Main: The meaning of life is 42 $ ./test.factor Test: The meaning of life is 42
As posted on RosettaCode.