Imagine we are servicing equipment where computer code is running; perhaps in a kiosk, or on a micro-controller in an oil refinery, or in the firmware of some rover on Mars.

Maybe our aim is to:

Note that these objectives all share the commonality of running in an imbedded chip environment where we typically don’t have access to mass storage, let alone an IDE (Integrated Development Environment), and hardware resources like RAM and CPU are limited. We can’t just shut off the system, tinker with it, and then restart it up again; so replacing the firmware with a newer version is simply not an option.

These constraints require us to interactively change the behavior of existing bits of compiled code, and do this while the entire system is running, without pausing its operation or shutting it down.

So we will need to do:

“Forward patching” where some pre-existing routine is re-defined, and any code added later will use the newer definition.

and we will especially need the ability to do:

“Backward patching” which is to swap out code of a function, and replace it with newer code, but where this exchange has an automatic ripple effect on ALL routines that are already using this function; so that the next time they execute they make use of the function’s new code❢

It is imperative that we be able to backward patch or forward patch ANY running code; we should be able to modify or redefine existing words (whether they be: functions, operators, variables, data structures, .. and also keywords for: conditionals, loops, directives, …) so that the whole system automatically gets updated with our changes, while still running — without any recompilation.

Almost no computer language can do forward patching of keywords, and none can do backward patching (although with some effort Forth can be modified to support this feature).

PAL natively supports both FP and BP out of the box.

Patching in PAL

To make a forward patch one simply mints the replacement word like any other. e.g. :

▪ func (a  b) ───‣ (r)
    ◌
    ◌
    ◌