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
main
function if one is specified. You'll still have to edit~/.factor-rc
to add theINCLUDING
/IN
macros 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.