PRINT:pc lineref1:lineref2 ZP:pc lineref1:lineref2
|pc||Optional — A postconditional expression.|
|lineref1||Optional — The line to be displayed, or the first line in a range of lines to be displayed, specified as a literal. Can be a label name, a numeric offset (+n) or a label name and a numeric offset. If omitted, the entire current routine is displayed.|
|:lineref2||Optional — The last line in a range of lines to be displayed, specified as a literal. To define a range, lineref1 must be specified.|
The PRINT command displays lines of code from the currently loaded routine. Use ZLOAD to load a routine. ZLOAD loads the INT code version of a routine. For the name of the current routine, access the $ZNAME special variable.
The output is sent to the current device. When invoked from the Terminal, the current output device defaults to the Terminal. You can establish the current device with the USE command. For the device ID of the current device, access the $IO special variable.
The PRINT and ZPRINT commands are functionally identical.
PRINT displays the INT code version of a routine. INT code does not count or include preprocessor statements. Completely blank lines from the MAC version of the routine, whether in the source code or within a multiline comment, are removed by the compiler and are therefore neither displayed nor counted in the INT routine. For this reason, PRINT displays and counts the following multi-line comment in the MAC routine as two lines, not three:
/* This comment includes a blank line */
The #;, ##;, and /// comments in the MAC code may not appear in the INT code, and thus may affect line counts and offsets. Refer to Comments in MAC Code for Routines and Methods for further details.
PRINT sets the edit pointer to the end of the lines it printed. For example, specifying PRINT then ZINSERT " SET y=2" inserts the line at the end of the routine; specifying PRINT +1:+4 then ZINSERT " SET y=2" inserts the line as line 5. The $TEXT function prints a single line from the current routine but does not change the edit pointer.
PRINT has two forms:
PRINT without arguments displays all the lines of code in the currently loaded routine.
PRINT with arguments displays the specified lines of code. PRINT lineref1 displays the line specified by lineref1. PRINT lineref1:lineref2 displays the range of lines starting with lineref1 and ending with lineref2 (inclusive).
The lineref arguments count lines and line offsets using the INT code version of the routine. After modifying a routine, you must re-compile the routine for PRINT to correctly count lines and line offsets that correspond to the source (MAC) version.
You can use the $TEXT function to return a single line of INT code.
An optional postconditional expression. InterSystems IRIS executes the PRINT command if the postconditional expression is true (evaluates to a nonzero numeric value). InterSystems IRIS does not execute the command if the postconditional expression is false (evaluates to zero). For further details, refer to Command Postconditional Expressions in Using ObjectScript.
The line to be printed or the first in a range of lines to be displayed or printed. Can be specified in either of the following syntactical forms:
+offset where offset is a positive integer specifying the line number within the current routine. +1 is the first line in the routine, which may be a label line. +0 always returns the empty string.
label[+offset] where label is a label within the routine and offset is the line number counting from the label (with the label itself counting as offset 0). If you omit the offset option, or specify label+0, InterSystems IRIS prints the label line. label+1 prints the line after the label.
A label may be longer than 31 characters, but must be unique within the first 31 characters. PRINT matches only the first 31 characters of a specified label. Label names are case-sensitive, and may contain Unicode characters.
The last line in a range of lines to be displayed. Specify in the same way as lineref1.lineref1 must be specified to specify lineref2. lineref1 and lineref2 are separated by a colon (:) character. No whitespace may appear between the colon and lineref2.
If lineref2 specifies a label or offset earlier in the line sequence than lineref1, PRINT ignores lineref2 and displays the single line of code specified by lineref1.
If lineref2 specifies a non-existent label or offset, PRINT displays from lineref1 to the end of the routine.
Given the following lines of code:
AviationLetters Abc WRITE "A is Abel",! WRITE "B is Baker",! WRITE "C is Charlie",! Def WRITE "D is Delta",! WRITE "E is Epsilon",! /* Not sure about E */ WRITE "F is Foxtrot",!
PRINT with no lineref arguments displays all nine lines, including the comment line.
PRINT +0 displays the empty string.
PRINT +1 displays the AviationLetters label.
PRINT +8 displays the /* Not sure about E */ comment line.
PRINT +10 displays the empty string.
PRINT Def or PRINT Def+0 display the Def WRITE "D is Delta",! line. This is a label line that also includes executable code.
PRINT Def+1 displays the WRITE "E is Epsilon",! line.
PRINT +0:+3 displays the empty string.
PRINT +1:+3 displays the first three lines.
PRINT +3:+3 displays the third line.
PRINT +3:+1 displays the third line; lineref2 is ignored.
PRINT +3:Abc+1 displays the third line. Both lineref1 and lineref2 are specifying the same line.
PRINT +3:abc+1 displays from the third line to the end of the routine. Line labels are case-sensitive, so the range endpoint was not found.
PRINT Abc+1:+4 displays lines 3 and 4.
PRINT Abc+1:Abc+2 displays lines 3 and 4.
PRINT Abc:Def displays lines 2, 3, 4, 5, and 6.
PRINT Abc+1:Def displays lines 3, 4, 5, and 6.
PRINT Def:Abc displays the Def WRITE "D is Delta",! line. Because lineref2 is earlier in the code, it is ignored.