Using References

Revision as of 00:54, 7 November 2008 by Lchrisman (talk | contribs)

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. A reference acts as an atomic element for array abstraction, and can be thought of as a pointer to a value (the value is often array-valued). with the simple syntax, \A, all dimensions of A are placed under the reference.

A reference displays in a result table as <<ref>>. You can view the value pointed to by the reference by double-clicking on the cell containing <<ref>>.

\[I,J]A

A list of zero or more indexes can be specified with taking the reference of a value. When indexes are specified, only those dimensions are swallowed by the reference. If there are other dimensions, the result returned will be an array of references. An empty list of references, \[]A, creates pointers to atomic values.

Dereference Operator: #R

When you have a reference (e.g., a pointer to a value), the dereference operator, #R, returns the value pointed to.

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 value 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 }
Var 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


Examples

Comments


You are not allowed to post comments.