Words That Stack Part I: Words

strict warning: Only variables should be passed by reference in /home/umuck/www/modules/book/book.module on line 559.

A word does not frighten the man who, in acting, feels no fear.-- Sophocles

Writing MUF programs is about defining words. You won't need your favorite dictionary to define these words, since the words and their definitions will be created by you, the programmer.

Since it is not possible to define a word without other words, MUF provides some basic words to define more complex words. These fundamental words are called primitive words. There are more than two hundred primitive words. However, the majority of programs only require a fraction of those. In these first exercises, we will only work with the most common and basic primitives.

There is no need to memorize and master all 219, but you should at least know how to get information about them. The Glowmuck server provides a help system for MUF which is accessible through 'man'. Typing 'man index' will give a list of topics which includes lists of the primitives. Additionally, a complete alphabetical list of the primitives is available at: http://glowmuck.sourceforge.net/mufdocs/primdefs.php.

Defining your own words is pretty simple. Each definition begins with a colon, the word that you are defining, the definition itself, and then a semi-colon to mark the end of the definition. In our example definition below, the word being defined is MyWord and the definition is 10 pop. Don't forget that the program listings in this book include line numbers as an aid to discussion, the line numbers are NOT part of the program.

  1. : MyWord
  2.   10 pop
  3. ;

You can, in turn, use words you have defined to define other words. Using the words you've defined are no different from using the primitive words, simply include them in your definition. In our next example, we have a definition for "FirstWord" and then a definition for "LastWord". LastWord uses FirstWord in its definition.

  1. : FirstWord
  2.   10 pop
  3. ;
  4.  
  5. : LastWord
  6.   "a string" FirstWord
  7. ;

Something important to note here is that words must be defined before they can be used. This means that your definition of a word must be in your program text BEFORE the first word that you use it in.

The very last word definition in your program text is the first one executed when your program is run. The word is typically named 'main' but is not required to be. This 'main' word often resembles a dispatcher's office since in most programs it is mainly composed of executions of the other words in the program, depending on the needs of the user of the program.

It is common for programmers to refer to words as procedures, functions, or methods. This is because words in MUF & FORTH perform the same duties that procedures, functions, or methods do in other languages. If it makes more sense to you to think of the user defined words as functions, procedures, or methods and the primitive words as commands or keywords, feel free to do so.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6> <blockquote> <iframe>
  • Lines and paragraphs break automatically.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • Use [# ...] to insert automatically numbered footnotes. Textile variant.
  • Web page addresses and e-mail addresses turn into links automatically. (Better URL filter.)
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <glow>, <muf>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.

More information about formatting options