Operator Scope of Action:
Operator First Added:
To make it easier to write rules succinctly, you may use the assignment:
$TheAttribute |= expression;
…which sets $TheAttribute to true if it is already true, or if the expression is true. Thus, if $TheAttribute is false, the expression is not checked and the overall result is false. An attribute that has no value set (or inherited) is evaluated as false.
In practical terms this means the left side, usually an attribute - is set to the right side value only if it is not already set at note level, i.e. its current value is either:
- The default for that attribute data type (for a string attribute "", for a number 0, for a date 'never', etc.)
- A prototype-inherited value (which in effect is simply altering the default value)
Attribute data type does not have to be Boolean
This fact makes the |= usage very useful for doing things like making code run only once - on the second pass the left side already has a value so no change occurs. This avoids things like looping causing multiple concatenation of strings.
$Urgent |= any(children,$Urgent)
A project is urgent if it has been declared to be urgent itself, or if any child is urgent.
Consider three different notes and their $Color. The first is new and uncustomised, $Color is the default. The second has a prototype setting $Color to "green". The third has been manually set to "bright blue" by the user. If this action is applied to all three notes:
$Color |= "bright red"
then two of the three notes will recolour. The first is has a default $Color so changes. The second note is green, but only because that is the default inherited via its prototype; it too, is re-coloured as it currently uses a default value. The third note is bright blue and this was expressly set at note level. So, as the latter does not use a default value, it remains bright blue.
If using |= assignments, it can be useful to have a means to reset an attribute to default to reenable an |= value assignment.
See also the logical AND assignment.