INFS3141 Advanced M/Caché ObjectScript Programming
RMU C&IS - Sample Quiz Material –
Array Traversal - $QUERY function

 

1. Assume K ^R S ^R(8,7)=1,^R(8,27)=2,^R(8,828)=3,^R(27,7)=4,
       ^R(8,4)=5,^R(27,39)=6,^R(27)=7,^R(8,88)=8,^R(27,3)=9

Draw the structure created by these assignments.  Use the drawing conventions as instructed previously in class (subscript references outside circles representing nodes; stored values inside nodes; nodes/subscripts in M collating sequence order)

Please implement the following:

SET REF="^R" FOR  SET REF=$QUERY(@REF) QUIT:REF=""  WRITE !,REF,"...",@REF

Please examine the output. Note which nodes of ^R on your drawing were visited by the $QUERY function traversal of ^R (and in which order) and which were ignored.

2. Assume K  S ^XA(6)=1,^XA(6,8)=2,^XA(6,29,63)=3,^XA(6,42)=4
^XA(42)=5,^XA(6,97)=6,^XA(6,29,117)=7,^XA(14,25)=8

Draw the structure created by these assignments.  Use the drawing conventions as instructed previously in class (subscript references outside circles representing nodes; stored values inside nodes; nodes/subscripts in M collating sequence order)

Predict which nodes will be visited by the $QUERY function traversal and in what order and which not. Check your prediction by implementing:

SET REF="^XA" FOR  SET REF=$QUERY(@REF) QUIT:REF=""  WRITE !,REF,"...",@REF

Discuss the difference between (1) @REF in $QUERY(@REF) and (2) in the argument list to the WRITE command: interpreting REF as an argument to the $QUERY function vs. interpreting REF as an argument to the WRITE command.

 

© 2004 by Robert Morris University