Arrow operator

Revision as of 22:37, 23 September 2025 by Lchrisman (talk | contribs) (→‎See also)

x->member

The arrow operator accesses a member or invokes a member function of an atomic value. This can be distinguished from the dot operator, A.I which operates on A at the array level. For example, suppose x is an array, then

x->member

would array abstract, applying the operator separately to every cell value of x. Whenever x is Null, the result value is Null.

The arrow can be typed either as a sequence of two characters, ->, or as the single right-arrow character, . To type the right-arrow character in Analytica, type the sequence:

\rarr[TAB]

where [TAB] is the tab key.

This operator only makes sense on certain atomic data types. Data types that include member fields (so that the variant x→member is meaningful) include:

Member assignment

In some contexts, with some data types, you can assign to a member using the syntax

x->member := newValue;

The right-hand side here is an expression that is evaluated.

x → memberFn(...)

Some data types include named member functions that can be called using the syntax

x -> memberFn( a, b, c )

Unlike standard function calls, the Analytica parser cannot detect whether the member function exists or has a compatible set of parameters. These determinations occur at evaluation time.

Some data types that have named member functions include:

x → (...)

Some data types are callables themselves (rather than having a named member function that is callable). These are called using the syntax

x -> (a,b,c)

Data types that are directly callable include:

x → [i]

New to Analytica 6.6

Some data types have indexable content in which internal elements can be accessed using the syntax, e.g.,

x->[5]

Data types in this category include:

  • Text values, e.g., "Hello world"->[5] returns "o".
    This is the same as SelectText("Hello world", 5, 5)
  • Binary data terms, in which x->[5] returns the fifth byte as an integer between 0 and 255.

x → [m..n]

The dot-dot operator can be placed inside the brackets to indicate that you want a subsequence rather than a single element. In addition, either «m» or «n» can be omitted to indicate "from the beginning" or "to the end". For example:

  • "Hello world"->[5..8] returns "o wo"
  • "Hello world"->[.. 8] returns "Hello wo"
  • "Hello world"->[5..] returns "o world"

When x is a [[Binary data term and a dot-dot is used in the brackets, the result is a new, smaller, binary data term.

The use of dot-dot inside the brackets is a special case as is not the same as these:

These examples would return lists of elements rather than sub-sequences of the original.

See also

Comments


You are not allowed to post comments.