Tinderbox v10 Icon

Functions

Tinderbox allows user-defined operators, also called 'functions'. Such operators are typically defined in notes inside the Library container in the document's built-in Hints container (if not present this should be added to the document) though they may be defined in other contexts too.

Notes in that container which have names enclosed in parentheses, such as /Hints/Library/(What’s This) are treated as documentation; all other notes are executed at document startup and after they are edited.

Why use functions?

Functions provide a 'define once / use multiple times' feature in documents, and allow:

What sort of things can functions do?

Functions comprise a set of action code instructions that perform a specific set of operations to achieve a specific outcome. In most cases, this will include acting upon optional input arguments provided to the function at the point where it is called (a.k.a., invoked) and optionally return results to the code that called (called) the function. A simple case is as shown in the example below (explained in more detail here):

function fAddTax(iPrice){return(1.18*iPrice);}; 

It is still possible to define a useful function that takes no input and returns no value but acts on the document based on the functions code, e.g. setting a selection of attribute values. In this mode the function is akin to calling a stamp, though calling a function may seem a more intuitive usage.

Functions fall into broad categories of use:

More about functions

The following sections should be read through completely on first encounter but are structured as small articles to assist cross-referencing and later reference for refreshing understanding or syntax.

Important note: all examples follow aTbRef naming conventions. These may seem verbose or over-descriptive to experienced programmers but are provided to help the learner, not the expert.

Aspects of using functions:


See also—notes linking to here: