Re: Factor

Factor: the language, the theory, and the practice.

Configuration Files

Saturday, January 8, 2011

#setup

Factor can use several configuration files as part of its startup routine.

factor-rc

At startup, Factor looks for a .factor-rc (or factor-rc on Windows) file in your $HOME directory. If found, it will attempt to run the contents of this file as Factor source code.

For example, if you’d like to have Factor print "Hello, World!" when it starts up, you can modify your factor-rc file to say:

USE: io
"Hello, World!" print

Then try and start Factor from the command-line and it should look something like this:

$ factor
Loading $HOME/.factor-rc
Hello, World!
IN: scratchpad 

More practically, if you want to always use a particular editor with Factor (e.g., MacVim), you can USE: it in your factor-rc:

USE: editors.macvim

For more information, see run-user-init.

factor-boot-rc

When performing the bootstrap process (e.g., making a new VM image), Factor looks for the .factor-boot-rc (or factor-boot-rc on Windows) file in your $HOME directory. In this file, you can use the require word to load vocabularies you use frequently.

For example, if you’d like to have the formatting vocabulary code loaded into the image (for the printf word), you can add this to your factor-boot-rc file:

USE: vocabs.loader
"formatting" require

The next time you bootstrap Factor, the new image should have loaded the formatting vocabulary.

For more information, see run-bootstrap-init.

factor-roots

By default, Factor looks in $FACTOR/core, $FACTOR/basis, $FACTOR/extra, and $FACTOR/work for vocabularies. It is frequently useful to specify additional vocabulary roots. Factor looks for the .factor-roots (or factor-roots on Windows) in your $HOME directory for additional vocabulary paths.

For example, if you want to use the code I’ve written as part of this blog, then you can checkout the re-factor code somewhere. Then, add the full path to the re-factor directory as a line in the factor-roots file. Next time you run Factor, you should be able to USE: vocabularies from re-factor.

For more information, see load-vocab-roots and add-vocab-roots.