Here are a few of my favorite example programs.


Networking and web


These are all runnable from the Factor UI if you have a good enough OpenGL driver -- just issue a command such as "spheres" run in the listener.


  • rot13 - rot13 "encryption"
  • roman - convert numbers to and from roman numerals
  • morse - convert strings to morse code and vice versa, and play morse code with OpenAL
  • base64
  • id3 - ID3 parser
  • usa-cities - parse a CSV file and extract information
  • benchmark.mandel - Mandelbrot fractal generator

Running the examples

Some of these demos define a MAIN: word. This means they are runnable from the Factor listener, by issuing a command such as the following,

"hello-unicode" run

Others are libraries, which means that after loading them with a command like this:

USE: roman

you can then get a list of words, and in some cases, API documentation:

"roman" about

and play around:

( scratchpad ) 123 >roman .

Understanding the examples

If you see an example refer to a vocabulary in its USING: list, you can get help for that vocabulary from the Factor listener:

"math.vectors" about

The about page gives a list of words with stack effects -- clicking on a word will display documentation for the word, if any, as well as its definition (which may not exactly match the source file definition, since its printed from its in-memory representation). For many vocabularies, a "Documentation" link at the very top gives an overview article as well.

If you see an example call a word you're unfamiliar with, make sure you load all required vocabularies by copying the example's USING: line into your listener, then use the help word to get help:

\ reverse help

This even works for bits of syntax:

\ MEMO: help


To see more examples of Factor code, download the Factor distribution and take a look in the core/, basis/ and extra/ directories. Also be sure to browse the online help, either from the Factor UI or online at http://docs.factorcode.org.

This revision created on Fri, 17 Jul 2009 23:16:32 by slava