Tinderbox v10 Icon

Parentheses: controlling parsing of code

By adding parentheses into action code, including queries, the oder of evaluation can be altered. When evaluating the most deeply nested terms are evaluated first.

Order of evaluating mathematical operators

Just as is the case in formal coding or formulas in an ordinary spread sheet, when it comes to carrying out mathematical operations there is an 'Order of Operations' (see more on Wikipedia).

Thus '1 + 2 × 3' can be considered ambiguous depending on whether the addition or the multiplication is done first. Thus the convention is

1 + (2 × 3) = 7 

but alternatively:

(1 + 2) × 3 = 9 

As is evident from the use of parentheses in these examples, by adding parentheses the user can indicate to Tinderbox their desired order of evaluation. Generally, additional parentheses are needed if the desired outcome is know to be the normal order of evaluation.

Order of evaluation in queries

Queries are used in agents, if(condition) tests and in find(query) operations. Queries are evaluated as read, i.e. left to right (start to finish), but in some cases additional hinting via parentheses can help both the parser and the user to understand their intent (especially when re-reading complex queries weeks or months later). Consider the outcome of this 5-term query, with terms A to E:

A | B & C | D | E 

compared to:

(A | B) & ( C | ( D | E ) ) 

Regardless of whether both evaluate the same way, the latter is much more easily understood in terms of the order things are done.

Query syntax is discussed in more detail here, and here.

Possible issues when using parentheses in a note title ($Name)

Because parentheses are used to indicate how to parse data, this is why it is a good idea—if possible—to avoid using a forward slash character within a note name as it can prove problematic for some Tinderbox automation operations.