Skip to main content

Value and Existence, and the $Data Function

Of course, any node can have its value changed at any time. Note that not all the nodes in the tree have assigned values. Two in particular, A(3) and A(5, "D"), only have children. They were created only because Set statements created their children. They can remain valueless, or you can give them values later on. This demonstrates another feature of ObjectScript arrays: locations can exist without having assigned values.

There is an important function that allows you to probe the nodes of a tree and learn about their status: $Data. If $Data returns a non-zero result, the node exists in some way.

Terminal


USER>write $data(A) ; has value and descendants
11
USER>write $data(A(3)) ; has descendants only
10
USER>write $data(A(3, 3)) ; has value only
1
USER>write $data(A(3, 5)) ; doesn't exist
0
USER>
Copy code to clipboard
FeedbackOpens in a new window