Using References
A Reference is a pointer to a value, which may be a single element or an array. References are useful when you want to work with an array of values which have different indexes.
Reference Operator: \A
The reference operator returns a reference to the value of «A». «A» is an expression which is evaluated in the current context. It may be a scalar value (single number or text) or an array value. A reference displays in a result table as «ref». To view view the value pointed to by the reference, double-click on the cell containing «ref».
\[I, J]A
If A is an array indexed by, I, J, and K, you put a list of indexes [I, J] after the "\" operator and before its operand «A», it generates an array indexed by K of references to arrays indexed by I, and J. More generally, the result is an array indexed by any indexes of A not in the index list of references to arrays with the indexes that are in the list. An empty list of references, \[]A, creates an array with all the indexes in A of pointers to the atomic values in A.
Dereference Operator: #R
The deference reference operator returns the value pointed to by a reference. #R, returns the value pointed to. Like almost all operators and functions, "#" array abstracts, so if R is an array index by J of References, #R returns an array indexes by the union of J and all the indexes in any arrays referenced as elements of R.
The operator has a lower precedence than subscript, so that #R[I = x] is equivalent to #(R[I = x]). In other words, when you have an array of references indexed by I, this is how you get to the thing pointed to by one of those references. If you need to slice the de-referenced value, then use (#R)[I = x].
When «R» is an array of references, #R will contain the union of all indexes from the de-referenced cells. You often want to avoid this, either because the resulting number of dimensions would be huge, or because two or more of the dereferenced values contain an implicit dimension (e.g., list), which would cause an error. Because references are often used to separate items with distinct dimensionality, or to store separate lists, these situations are common for cases where references are used. Thus, you will often need to explicitly loop with For..Do or other looping constructs, rather than letting array abstraction take care of it for you.
Comparisons
Less-than and greater-than comparisons are not defined for references and always return Null.
Testing equality of references gets a bit tricky, and in general it is a bad practice to rely on equality of references. References are equal only if they point to the exact same data in memory. The values pointed to by two references can be identical while the references are not considered equal. For example:
\"Hello" = \"Hello" → 0 { they point to two different instances of "Hello" in memory }Local s := "Hello" Do (\s = \s) → 1 { Now they point to the same instance in memory }
References to equal numbers, null, or undef do test for equality.
\1 = \1 → 1\Null = \Null → 1
Enable comment auto-refresher