Modules: how to overwrite system functions?

Carl Sassenrath, CTO
REBOL Technologies
5-Sep-2006 17:30 GMT

Article #0045
Main page || Index || Prior Article [0044] || Next Article [0046] || 6 Comments || Send feedback

The question has been asked: how does a program overwrite system functions? For example, if you want to use your own custom send function, how would you do that?

Before the question can be answered, you (the programmer) must decide if:

  1. you only need the new function in your own code, or

  2. you need all system code to use the new function.

The first is easy. You would just overwrite the function word:

send: func [....] [... my new function ...]

This would change the send function for your "current context" - your program (script).

The second question is deeper, because you must know that your change is compatible with the rest of the system. Assuming that it is, there are two mechanisms to make the system-wide change:

  1. Provide the "patch" early in the boot process. The new function must be set before any other modules import the function. REBOL would provide a method for doing this (similar to the REBOL.r file, but with greater security).

  2. Request a system-wide re-set for the new function. This method would overwrite the function variable in all modules (or in specific modules). But, there are issues to consider. For instance, what if a module has made its own changes to the function? Now there is a conflict. One solution is for the re-set function to provide a /force refinement that would reset all instances. When the refinement is not set, only those instances that refer to the original definition would be changed.

Note: More information to be provided during testing stages.


I believe that we need to keep this mechanism simple enough that it is easy for us to all understand (otherwise, it will become a problem for everyone).


Updated 26-May-2024 - Edit - Copyright REBOL Technologies -