Share via


5.4.5.8 Print Statement

A <print-statement> writes data to the file underlying <marked-file-number>.

 print-statement = [("Debug" / "Me") "."] "Print" marked-file-number "," [output-list] 

Static Semantics.

§ The semantics of <marked-file-number> in this context are those of a <file-number> element that consisted of that same <marked-file-number> element.

Runtime Semantics.

  • An error (number 52, "Bad file name or number") is raised if the file number value (section 5.4.5.1.1) of <file-number> is not a currently-open (section 5.4.5.1) file number (section 5.4.5).

  • If <output-list> is not present, the line termination sequence (section 5.4.5) is written to the file associated with file number value starting at its current file-pointer-position. The current file-pointer-position is set immediately after the line termination sequence.

  • Otherwise, for each <output-item> in <output-list> proceeding in left to right order:

  • If <output-clause> consists of an <output-expression>

    1. The <output-expression> is evaluated to produce an output string value and characters of the string are written to the file associated with file number value starting at its current file-pointer-position.

    2. The current file-pointer-position now points to the location after the output characters of the string.

    3. If while performing any of these steps the number of characters in the current line (section 5.4.5) reaches the maximum line length (section 5.4.5) the line termination sequence is immediately written and output continues on the next line.

  • If <output-clause> consists of a <spc-clause>

    1. If space count (section 5.4.5.8.1) is less than or equal to maximum line length of the file number value or if the file number value does not have a maximum line length, let s be the value of space count.

    2. Otherwise, space count is greater than the maximum line length. Let s be the value (space count modulo maximum line length).

    3. If the is a maximum line width and s is greater than maximum line width minus current line position let s equal s minus (maximum line width minus current line position). The line termination sequence is immediately written and current file-pointer-position is set to beginning of the new line.

    4. Write s space characters to the file associated with file number value starting at its current file-pointer-position and set the current file-pointer-position to the position following that last such space character.

  • If <output-clause> consists of a <tab-clause> that includes a <tab-number-clause> then do the following steps:

    1. If tab number (section 5.4.5.8.1) is less than or equal to maximum line length of the file number value or if the file number value does not have a maximum line length, let t be the value of tab number.

    2. Otherwise, tab number is greater than the maximum line length. Let t be the value (tab number modulo maximum line length).

    3. If t less than or equal to the current line position, output the line termination sequence. Set the current file-pointer-position is set to beginning of the new line.

    4. Write t minus current line position space characters to the file associated with file number value starting at its current file-pointer-position and set the current file-pointer-position to the position following that last such space character.

  • If <output-clause> consists of a <tab-clause> that does not includes a <tab-number-clause> then the current file-pointer-position is advanced to the next print zone (section 5.4.5) by outputting space characters until (current line position modulo 14) equals 1. o If the <char-position> of the <output-item> is ",", the current file-pointer-position is further advanced to the next print zone by outputting space characters until (modulo 14) equals 1. Note that the print zone is advance even if the current file-pointer-position is already at the beginning of a print zone.

  • If the <char-position> of the last <output-item> is neither a "," or an explicitly occurring ";" the implementation-defined line termination sequence is output and the current file-position-pointer is set to the beginning of the new line.

  • The output string value of an <output-expression> is determined as follows:

    • If the evaluated data value of the <output-expression> is the Boolean data value True, the output string is "True".

    • If the evaluated data value of the <output-expression> is the Boolean data value False, the output string is "False".

    • If the evaluated data value of the <output-expression> is the data value Null, the output string is "Null".

    • If the evaluated data value of the <output-expression> is an Error data value the output string is "Error " followed by the error code Let-coerced to String.

    • If the evaluated data value of the <output-expression> is any numeric data value other than a Date the output string is the evaluated data value of the <output-expression> Let-coerced to String with a space character inserted as the first and the last character of the String data value.

    • If the evaluated data value of the <output-expression> is a Date data value the output string is the data value Let-coerced to String.

    • Otherwise, the output string is the evaluated data value of the <output-expression> Let-coerced to String.