____ ____ ____ ____ 
||n |||i |||m |||f ||
||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|

	

the nimf guide : words

Words are the building blocks of nimf programs. Words can be thought of similarly to functions, or more accurately procedures, found in other languages. In nimf they do not return anything; that is, they leave things ont he stack or in memory, but do not "return" a value like a function might in, say, C or Rust or Python.

Like in most forth-like languages, words in nimf should be as small as is reasonable to perform a single action. You can then combine words, often by putting them into other words, to create larger functionality. You may find that if you create really long monster words, it becomes hard to trace their meaning. Having well named words that succinctly describe their actions is very important.

Using Words

You have already seen many words in use. For example `j emit. In that example, emit is a word (it happens to be a builtin word). When the interpreter reaches it, it will jump into its definition and start executing words there (in the case of builtins, those "words" will be golang functions). Using words is one of two actions you can do in nimf:

  1. Add an integer to the stack
  2. Use words to manipulate the stack/memory integers

Creating New Words

That leaves the obvious question: "how do I create a new word?". Well, there is a syntax for that (some of the very little syntax that exists in nimf).

: word-name ( usage comment ) "Hello!" str.print-buf ;

A word definition starts with : and is followed up with the name of the new word (the name will be used to call the word). It is customary to then include a comment that describes how to use the word, usually it involves what is taken from the stack and what is left on the stack. After the comment comes words, numbers, and string literals, as needed. Then to end the word definition you use the word ;. Pretty simple, right?