Printing

Controlling the Depth of Printing

The Inspector allows you to print recursively. For instance, if a frame contains a slot that holds a frame or array, you can use the Inspector to print both the enclosing frame and the contained frame. This works for the full depth of a structure. As you can imagine, this may or may not be what you intended. Picture displaying GetRoot() with no limit on the printing! Fortunately, there is a mechanism for controlling the depth of this recursive printing.

FIGURE 8.4 : The printDepth popup in the Inspector window.


The printDepth global variable contains an integer that sets the depth of recursive printing. The higher the number, the more levels that print. The default value for this variable is 1. You can set this variable directly from the Inspector, or by using the printDepth popup (see FIGURE 8.4). The following frame serves as a good test for showing these different levels:

f := {
   name: "Neil",
   height: 73.25,
   children: [
      {
         name: "Nicholas",
         height: 48,
         children: [],
      },
      {
         name: "Alexander",
         height: 43,
         children: [],
      },
      {
         name: "Nathaniel",
         height: 24,
         children: [],
      },
   ]
}
Using print depths from -1 to 2, TABLE 8.2 shows that each change yields one more level of detail. It would take a print depth of 3 in order to see the full contents of the example frame.

Changing the print depth.
PrintDepth -1PrintDepth 0PrintDepth 1PrintDepth 2
Print(f);

{#4413AE9}

Print(f);

{name: "Neil",
height: 73.2500,
children:[#4413AD1]}

Print(f);

{name: "Neil",
height: 73.2500,
children: [{#441A051},
{#441A075},
{#441A099}]}

Print(f);

{name: "Neil",
height: 73.2500,
children: [{name: "Nicholas",
height: 48,
children: [#441A045]},
{name: "Alexander",
height: 43,
children: [#441A069]},
{name: "Nathaniel",
height: 24,
children: [#441A08D]}]}


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996