Constants

A constant is an identifier for a static value.

Inkling supports named constants in the global program scope. Constants cannot change during execution. Constant names are case-sensitive and follow standard Inkling identifier rules.

Supported

  • declarative typing.
  • inferred typing.

Not Supported

  • cyclical references.
  • nested declaration.

Unsupported constant usage is reported as an error by the Inkling compiler and disables brain training.

Declaration

Constants must be assigned a value when they are declared. Valid assignments include literals or deterministic expression that include operators, literals, and other constants.

When constants have a declared type, the Inkling compiler validates that the assigned value matches the specified type.

Example constants with declarative type

const NumericConst1: number = 100
const NumericConst4: number<0 .. 2> = 3 * (5 / 2) - 7
const StructConst1: {X: number, Y: string} = {X: 3, Y: "Foo"}

Example constants with inferred type

const MaxVelocity = 100
const MinVelocity = 0
const DebugMode = true

Usage

Constants do not need to be declared before they are used. Constants can replace any valid literal provided the type of the constant is compatible with the type of the context where it is used.

const TrackLength = 0.5
const MaxVelocity = 1.0

type CartState {
    CartPosition: number<-TrackLength / 2 .. TrackLength / 2>,
    CartVelocity: number<-MaxVelocity .. MaxVelocity>,
}

Built-in constants

Inkling provides the following built-in constants

Constant Value Type
true 1 number<1>
false 0 number<0>