Literals/String: Difference between revisions

Content deleted Content added
Dinosaur (talk | contribs)
Dinosaur (talk | contribs)
→‎{{header|Fortran}}: After going for a stroll to the letterbox...
Line 530: Line 530:
TEXT = 'He said "That''s right!"' !Though one may dabble in inconsistency.
TEXT = 'He said "That''s right!"' !Though one may dabble in inconsistency.
</lang>
</lang>
Producing a source file containing a block of text that will be presented as output in the same layout (new lines and all) is only possible if the added layout stuff (generating the required new line starts) in the source is disregarded...
Producing a source file containing a block of text that will be presented as output in the same layout (new lines and all) is only possible if the added layout stuff (generating the required new line starts) in the source is disregarded. But if one accepts a few constraints, the following shows a possible approach:
<lang Fortran>
INTEGER I !A stepper.
CHARACTER*666 I AM !Sufficient space.
I AM = "<col72
C 111111111122222222223333333333444444444455555555556666666666
C 123456789012345678901234567890123456789012345678901234567890123456789
1 <col72
2 I AM <col72
3 <col72
4 THAT I AM <col72
5"

Chug through the text blob.
DO I = 0,600,66 !Known length.
WRITE (6,1) I AM(I + 1:I + 66) !Reveal one line.
1 FORMAT (A66) !No control characters are expected.
END DO !On to the next line.
END
</lang>
With old-style fixed-format source, rather amusingly there is space for sixty-six characters of text per line and this is the canvas. Any usage of tab characters must be resolved into spaces (and some compilers count up to 72 oddly when tabs are involved) and likewise with new lines. A surprise was provided to an old-time card flapper when it became apparent that trailing spaces were ''not'' being incorporated into the text literal unless the "<col72" markers were appended to column seventy-two of the source. An old-time card deck lacking sequence numbers in columns 73-80 once copied to disc might thereby compile incorrectly! Similarly, the source text highlighter here does not fully recognise the odd tricks available for Fortran syntax, apparently deeming the comments a part of a text literal. The F90 compiler's highlighting does, and notes that text beyond column 72 is not Fortran code.

The text blob could instead be an array, but in that case, each line would have to be delimited by quotes and a comma added, reducing the width of the canvas. But with a single blob of text, the output statement must step through the parts of the blob to extract the lines. If the statement were <code> WRITE (6,1) I AM</code> then only the first 66 characters of I AM would be rolled forth. If the format code were just A instead of A66, then all the text would be rolled, but the output would not be presented with 66 characters per line. So, some complications lead to :
<pre>

I AM

THAT I AM



</pre>


=={{header|friendly interactive shell}}==
=={{header|friendly interactive shell}}==