The listener
Factor handbook ยป Developer tools

Next:Editor integration


The listener evaluates Factor expressions read from the input stream. Typically, you write Factor code in a text editor, load it from the listener by calling require, reload or run-file, and then test it interactively.

The classical first program can be run in the listener:
"Hello, world" print
Hello, world

New words can also be defined in the listener:
USE: math.functions : twice ( word -- ) [ execute ] [ execute ] bi ; inline 81 \ sqrt twice .
3.0

Multi-line expressions are supported:
{ 1 2 3 } [ . ] each
1 2 3

The listener will display the current contents of the datastack after every line of input.

If your code runs too long, you can press C-Break to interrupt it (works only on Windows). To enable this feature, run the following code, or add it to your Startup initialization file:
USING: listener namespaces ; t handle-ctrl-break set-global

The listener can watch dynamic variables:
Watching variables in the listener

Nested listeners can be useful for testing code in other dynamic scopes. For example, when doing database maintenance using the db.tuples vocabulary, it can be useful to start a listener with a database connection:
USING: db db.sqlite listener ; "data.db" <sqlite-db> [ listener ] with-db

Starting a nested listener:
listener ( -- )


To exit a listener, invoke the return word.

The listener's mechanism for reading multi-line expressions from the input stream can be called from user code:
read-quot ( -- quot/f )