Extensions to Functions

In some cases, in a library or document, it's necessary to extend a function. For example, the Simplify function is defined in the Core library but there are simplifications that we want in the Simplify function that have be implemented in the Math library, the Trig library, and so on. Extensions provide a way to implement a function that has clauses spread out across multiple libraries.

The basics of extending object definitions is explained in Extending Object Definitions. Here we cover properties that can be used when object definitions that have clauses are extended.

The Override Property

Suppose the list of libraries in the current document is LibraryA, LibraryB, and LibraryC and all three libraries define MyFunction with one or more clauses in each library. The normal function call would include the clauses from LibraryC, followed by the clauses from LibraryB and finally the clauses from LibraryA.

If the object definition for MyFunction in LibraryC has the Override property, then a call to that function will only include the clauses from LibraryC. Any clauses from libraries that are referenced will not be included in this case.

Similarly, if the object definition in LibraryB had the Override property instead of the one in LibraryC, then the function call would include the clauses from LibraryC and LibraryB, but not the clauses from LibraryA.

The FunctionCall Object

The FunctionCall object provides a way to execute the clauses in a function starting from a particular library and including all of the clauses from that library up to the top of the list of libraries in the current document. FunctionCall and Base are normally only used with objects that have extensions (additional object definitions with the same name and type) in more than one library.

The "Base" Library Object

Used in the FunctionCall object. If you call Base.MyFunction in a clause in LibraryC and the list of libraries in the current document is LibraryA, LibraryB, and LibraryC, then the function that is executed will contain any clauses from MyFunction in LibraryB followed by any clauses from MyFunction in LibraryA. If at some later time, the list of libraries is changed, Base.MyFunction will then build the clauses for MyFunction by starting with the first library above LibraryC in the library list and continuing to the top of the list.

FunctionCall[Base, …] is used when the intent is for the function to include all of the functionality defined in the base libraries no matter what the name of the next library in the library is. One example of where Base would be used is in a function that needs to call the base functionality first, and only do something new if the base functionality doesn't return a result. Normally, the clauses in the base libraries would be executed after the clauses in the extension.