MAIN not executed by Factor on command line

时光总嘲笑我的痴心妄想 提交于 2019-12-10 11:44:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!