O'Reilly logo

Seven More Languages in Seven Weeks by Bruce Tate, Jack Moffitt, Frederic Daoud, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Day 2: Painting the Fence

Today, we will move our exploration of Factor from the Listener to source files. We’ll learn how to define words, organize them into modules called vocabularies, run them as standalone programs, and test them with unit tests.

Defining Words

We’ve been using Factor words that are defined in the library. Let’s see how we can define our own words. A word definition starts with a colon, a space, and the name of the word. Then comes the stack effect, the code for the word, and finally a space and a semicolon. For example:

 
: add-42 ( x -- y ) 42 + ;

That defines a word which adds 42 to the number that’s on the stack. The ( x -- y ) part is the stack effect: the number of values that the word takes from the stack and pushes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required