main
如果指定了一个函数, Factor 现在将执行一个函数。您仍然需要编辑~/.factor-rc
以添加INCLUDING
/IN
宏,以便 Factor 将在当前目录中搜索代码。
~/.factor-rc:
! Andrew Pennebaker
! INCLUDING macro that imports source code files in the current directory
USING: kernel vocabs.loader parser sequences lexer vocabs.parser ;
IN: syntax
: include-vocab ( vocab -- ) dup ".factor" append parse-file append use-vocab ;
SYNTAX: INCLUDING: ";" [ include-vocab ] each-token ;
脚本main.factor:
#! /usr/bin/env factor
USING: io math.parser ;
IN: scriptedmain
: meaning-of-life ( -- n ) 42 ;
: main ( -- ) meaning-of-life "Main: The meaning of life is " write number>string print ;
MAIN: main
测试因素:
#! /usr/bin/env factor
INCLUDING: scriptedmain ;
USING: io math.parser ;
IN: test
: main ( -- ) meaning-of-life "Test: The meaning of life is " write number>string print ;
MAIN: main
例子:
$ ./scriptedmain.factor main:生命的意义是42 $ ./test.factor test:生命的意义是42
正如在RosettaCode上发布的那样。