Skip to content

Const Extension

2026-11-30

  • Extension introduced in 5.0.4, then enabled in 5.0.5 upon the incorporated support in the LRAUV codebase.

Syntax

The const $NAME = <static expression> syntax allows to introduce compile-time constants, that is, for numbers that would otherwise be repeated and kept in sync by hand. While improving consistency and mission documentation, this is intended to further facilitate the use of the macro and array extensions.

Define any constants at the top of the script, before arguments, and use them wherever a static value is expected:

mission Example {
  const $NUM_DEPTHS = 20
  const $LAST = $NUM_DEPTHS - 2

  arguments {
    Depth[1..$NUM_DEPTHS] = NaN meter
  }

  macro $j = 2..$LAST {
    aggregate Leg$j {
      run in sequence
      syslog important "depth=" + Depth[$j + 1]~meter
    }
  }
}
  • The constant name must start with $.
  • The static expression is a number, or an expression using +, -, numbers, and previously defined constants; its value must be a non-negative integer.
  • Names after $ (constants, macro variables) can now also contain digits and _ (e.g., $NUM_DEPTHS), after a letter.
  • VS Code extension: hover, go to definition, references and rename for constants; completion of constants (and of the macro variable in array indexes).
  • Note: missions using these features can only be loaded by vehicles running a version of the LRAUV software that supports them.

Lint

There is a corresponding lint to suggest constants for the numbers written in ranges.

  • "Possible use of const": the upper limits of array declarations and macro ranges written as numbers, anywhere in the file, grouped by value with their lines.
  • "Possible use of 'array' extension": also a hint to use a constant for the upper limit (once per distinct limit).

As an example of a reported lint:

Possible use of 'const':

    The number 7 is used in 3 ranges:
      line 35: Lat[1..7]
      line 40: Lon[1..7]
      line 483: macro $i = 2..7
    Consider using a constant instead, e.g.: const $MAX_... = 7