INFS2140/INFS3141 Advanced M/Caché ObjectScript Programming
RMU C&IS – Drawing Array Structure Diagrams

Drawing conventions for M Array Structure Diagrams (in /Caché ObjectScript and GT.M)

• root node (name of local or global array) at top
• subscript references outside circles representing nodes
1. ^R represents unsubscripted root node reference for array ^R
2. 2 (1st Level) represents reference ^R(2)
3. 17 (1st Level) represents reference ^R(17)
4. 41 (2nd Level) represents reference ^R(2,41)
5. 6 (2nd Level) represents reference ^R(17,6)
6. 8 (2nd Level) represents reference ^R(17,8)
7. 34 (2nd Level) represents reference ^R(17,34)
• stored values inside nodes (empty circles: node references with no stored values)
• nodes/subscripts (in group of sibling nodes) in standard M collating sequence order This diagram (seven nodes) is the result of the following five SETs:

SET ^R(2,41)=36,^R(17)=5,^R(17,6)=2,^R(17,8)=62,^R(17,34)=14

Most common ways to read these references out loud:

^R “up-arrow R”

^R(2) “up-arrow R sub 2”

^R(2,17) “up-arrow R sub 2 comma 17”

The use of “up-arrow” comes historically from the keyboard of the Digital PDP-11, which had an “up-arrow” ­ above the 8 where the caret symbol is today.

Note: there is no explicit set command to establish nodes ^R or ^R(2), they are implicitly established with no stored value by the command SET ^R(2,41)=36

What will the \$DATA function return for each of these nodes? (0, 1, 10, 11)

• WRITE \$DATA(^R)
• WRITE \$DATA(^R(2))
• WRITE \$DATA(^R(17))
• WRITE \$DATA(^R(2,41))
• WRITE \$DATA(^R(17,6))
• WRITE \$DATA(^R(17,8))
• WRITE \$DATA(^R(17,34))

What will the \$DATA function return for this node? (0, 1, 10, 11)

• WRITE \$DATA(^R(17,26))

Notes on the \$DATA function:

The two questions to ask regarding a node (in order to know \$DATA function result for that node) are:

• Does the node have any descendents?
• Does the node have a stored value?

 \$DATA results No descendents Has descendents No stored value 00 Node doesn’t exist \$DATA returns 0 10 Intermediate or root node: no stored value; reference only Has stored value 01 Leaf node or only node \$DATA returns 1 11 Intermediate or root node: has stored value

Notes on array structure:

• This type of array, used in GT.M and Caché ObjectScript, is called an associative array.
• The nodes with no descendents are called leaf nodes. What are the leaf nodes in this diagram?
^R(2,41), ^R(17,6), ^R(17,8), ^R(17,34)
• Nodes shown on diagram as empty circles with a fill color (see ^R and ^R(2) in diagram above) have no defined value – they are not stored and only serve as reference points in the array structure. (Obviously, you don’t have to color in the empty circles on a diagram – just leave them empty to signify “no defined value.”)
• Nodes which have the same path to the root node (same ancestors) are called siblings. Which sets of nodes are sets of siblings in this diagram?
• Using the \$DATA function to detect whether array nodes exist in any form: if the array node reference is not present in the array in any form you will get a returned value of zero (0) (= false). Any other value (1, 10, 11) is (obviously) non-zero (= true). Thus the \$DATA function can be used to determine if an array node reference is present in an array.

Notes on the diagram:

• 2 in the diagram above next to a node in the 1st level of subscripts denotes the complete reference: ^R(2)
• This diagram has numbers for all the subscripts; subscript values may also be arbitrary character strings in GT.M and Caché ObjectScript.

Updated: 2012-10-08 \$H 62738

Valerie J. H. Powell, R.T.(R), Ph.D.

© 2012 by Robert Morris University