MAIN not executed by Factor on command line

215 Views Asked by At

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)

2

There are 2 best solutions below

0
On BEST ANSWER

Factor now executes a MAIN function for command line scripts that specify one. (See GitHub)

1
On

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.