As noted already, redefining a word does not change the existing action for words already compiled. It is sometimes necessary to change the behavior of a word in such a way that any words already compiled use the new action. This can be done in at least two ways.
1. Vectored Execution
If it is known that a word may need to have its action changed, there is a mechanism for "deferred execution". The method defines a word that executes a stored address (vector). Changing the stored address changes the behavior of the word.
I used this feature in the permutation package to permit a switch, after the fact, between left-to-right and right-to-left multiplication:
DEFER Direction : Left->Right ['] NOOP IS Direction ; : Right->Left ['] SWAP IS Direction ;
The behavior of the word Direction is switched between a NOOP (no operation) and SWAP. This switchable word is used at the start of the code for P*.
Vectored execution is also used in the "print to file" code. Win32Forth, like many other Forth systems, uses deferred execution for basic output words EMIT, TYPE, and CR. We can switch the behavior of these words. During printing to a file we install versions that not only print to the console but also send output to a file.
Vectored execution can also be used effectively in development to test several versions of a word: The code is written with a vectored word, and alternatives can be installed "on the fly".
For clarity of code, it is important to document, at the point where a vectored word is created, the type of behavior that will be filled in.
2. Patching a definition
The dictionary entries themselves occupy accessible memory. One can often change the behavior of an existing word (e.g., to fix a bug) by altering an existing dictionary entry directly. Details of this process depend on the implementation of Forth and are beyond the scope of this article.