Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: common equivalent

...

Note three different styles: all on a single line, or on multiple lines, one per expression, either ending with the vertical bar or with the expression, but in either case the expressions are lined up, and the vertical bars are lined up. These styles are not required by the language syntax but are recommended for readability of your code.

Another example, in a function to convert GMT time to Mountain Time during 2020:

Code Block
    makeMT = function(ts){
      MST = time:add(ts,{"hours": -7});
      MDT = time:add(ts,{"hours": -6});
      MDT > "2020-11-01T02" => MST |
      MST > "2020-03-08T02" => MDT |
                               MST
    }

There is a common special case of the ternary expression, in which the predicate expression and the consequent expression are identical:

Code Block
<pred> => <pred> | <alternate expr>

To avoid repeating the predicate expression, this can be replaced by the simpler, equivalent Boolean expression:

Code Block
<pred> || <alternate expr>

This is especially useful if <pred> is an involved or time-consuming expression. This form is often used to provide default values for event attributes.