IDL 8.4 also introduces a new boolean “type”, which is actually not a real type, but just a metadata flag on byte variables1. This boolean flag allows for better understanding of the purpose of the variable. For example, JSON_SERIALIZE can convert boolean IDL variables to boolean JSON declarations.

Create boolean variables by converting existing variables with the BOOLEAN function or by creating arrays with BOOLARR. The rules used to convert variables to boolean are not the normal truth values in IDL2; they are the rules used with the logical_predicate compile option is set, i.e., null, empty, or 0 values are false, everything else is true:

IDL> print, boolean(indgen(5))
   0   1   1   1   1
IDL> print, boolean(['', 'yes', 'no'])
   0   1   1

There are also convenient new !true and !false boolean system variables:

IDL> help, !true
<Expression>    BOOLEAN   = true (1)
IDL> help, !false
<Expression>    BOOLEAN   = false (0)

  1. For those familiar with IDL’s internal API, IDL 8.4 introduces a IDL_V_BOOLEAN flag that is used to mark the flags field of an IDL_VARIABLE structure. There is also an IDL_BOOLEAN macro to determine if a variable is a boolean. The macro requires that the IDL_V_BOOLEAN flag is set and that the variable is of type byte. 

  2. Thank goodness. The “normal” IDL rules for the truth value of integers depend on the lowest order bit of the integer, i.e., whether the integer is even or odd:

    IDL> if 1 then print, 'true' else print, 'false'
    true
    IDL> if 2 then print, 'true' else print, 'false'
    false
    IDL> if 3 then print, 'true' else print, 'false'
    true