问题
I'm not seeing any output from my Hello World program.
$ cat hello.factor
USE: io
IN: hello
: hello ( -- ) "Hello World!" print ;
MAIN: hello
$ factor hello.factor
$
(No output)
$ factor -run=hello
Vocabulary does not exist
name "hello"
$ factor -run=hello hello.factor
$
(No output)
回答1:
MAIN:
defines an entry point for a vocabulary when the vocabulary is passed to run
, not necessarily when it is "loaded" from the command line, as you're doing above. The easiest way to make this work is to simply issue "hello" run
from the UI listener.
To actually call the hello
word as a script, simply place a call in the top level, like so:
USE: io
IN: hello
: hello ( -- ) "Hello World!" print ;
! This is the important part
hello
Alternatively, you can load and run the vocabulary from the command line with the -run=vocab
command line argument. For instance, factor -run=hello
.
There is some more information on this in the docs. Try running "command-line" about
in the listener.
回答2:
Factor now executes a MAIN function for command line scripts that specify one. (See GitHub)
来源:https://stackoverflow.com/questions/7101575/main-not-executed-by-factor-on-command-line