Skip to main content
Version: 0.4.12

Indexing

Indexing is done via 3 different methods:

  1. The index function.
  2. Subscripting
  3. Dot Access

While indexing is primarily done via subscripting and dot access, both these operations are best defined via the index function

The index function#

The index function has two arities.

Arity of 2#

Index behavior is defined as follows when operating in the two arity mode:

Value TypeAllowed IndexesReturns
objectstringValue at key
arraynumberValue at offset
stringnumberCharacter at offset
nullstring, numbernull

All other signatures should raise RuntimeErrors.

Arity of 3#

Index behavior is defined as follows when operating in the two arity mode:

Value TypeAllowed IndexesReturns
arraynumber or nullArray of values between offsets
stringnumber or nullString of characters between offsets

All other signatures should raise RuntimeErrors.

Subscript Access#

Subscript access is equivalent to calling the index function, using the following table of syntactic sugar

Subscript SyntaxIndex Syntax
foo[bar]index bar foo
foo[bar:]index bar null foo
foo[:bar]index null bar foo
foo[bar:baz]index null bar foo
foo[:]index null null foo

Dot Access#

Dot access is equivalent to the 2-arity index function with the right hand side interpereted as a string.

For example, foo.bar is syntactic sugar for index "bar" foo

Indexing strings#

Strings are indexed via full unicode codepoints rather than with surrogate pairs. For example, "๐Ÿ˜Ša"[0] == "๐Ÿ˜Š" and "๐Ÿ˜Ša"[1] == "a". MistQL treats the two codepoints in modifiers as separate characters, as in "๐Ÿ‘‹๐Ÿฝ"[0] == "๐Ÿ‘‹".