"Sputnik" help  
Sputnik Help
Rule Replace


This demonstrates how to create a function that can replace a Sputnik user defined function by the same name.

Before reading this section make sure to read all User Functions and understand it.


The replace rule in Sputnik allows you to replace a user-defined function with a custom function that has the same name. By using the "r" flag or rule, you can override the existing implementation of a function and provide your own version.

When a user-defined function is replaced, all calls to that function will be directed to your custom function instead. This can be useful if you want to modify the behavior or extend the functionality of an existing function in your codebase.

It's important to exercise caution when replacing user-defined functions because other parts of the codebase may rely on the original functionality. By replacing a function, you may introduce unexpected behavior or break compatibility with existing code.

The example provided demonstrates how to replace the user-defined function Cat() with a custom function. The original function simply outputs "Meow!", but the custom function overrides it and outputs "Custom Cat: purr" instead. When the Cat() function is called, it invokes the custom function instead of the original function, resulting in the custom output.

When using the replace rule, it's important to ensure that your custom function provides the necessary functionality expected by the original function. This may involve replicating the behavior of the original function or providing additional features on top of it.

By using the replace rule, you can modify and extend the behavior of user-defined functions in your code. However, it's crucial to consider the implications and potential impact on other parts of your codebase that rely on the original function's behavior.


User Functions
Rule Override


Example of replacing a user defined function using the "r" flag/rule:

Function Cat()
    say "Meow!";


"r" Function Cat()
    say "Custom Cat: purr";
// Custom Cat: purr

// This forces all calls to Cat() (user defined) function to go to your
// function instead this can prove useful if you are extending
// the functionality of a user defined function.
// Be careful however since other code might expect the old functionality
// and suddenly find the function works a bit differently which may be a problem

That is how to replace a user defined function.

Cheryl (uberfox@hotmail.com)