Next: , Previous: , Up: READ OUT and WRITE IN   [Index]


7.7.2 C-INTERCAL I/O

INTERCAL-72 C-INTERCAL CLC-INTERCAL J-INTERCAL
no version 0.07+ version 0.05+ no

C-INTERCAL’s method of character-based (rather than numeric) input and output is known as the Turing Tape method; it is a binary (character-set-agnostic) input/output mechanism. To specify that C-INTERCAL-style I/O is being used, an array must be used as the argument to READ OUT or WRITE IN; as the syntax is the same as for CLC-INTERCAL’s I/O, command-line arguments and the capabilities of the version of the compiler being used serve to distinguish the two mechanisms.

The character-based input writes as many characters into a tail or hybrid array as will fit, one character in each element. The number that’s written into the array is not the character code, though, but the difference between the character code and the previous character code, modulo 256. (To be precise, the code is the new character minus the previous character, or 256 minus (the previous character minus the new character) if the previous character had a higher character code; the ’previous character’ is the previous character from the input, not the previous character written into the array.) End-of-file causes 256 to be written into the array. The concept is that of a circular tape containing all the characters, where the program measures how many spaces it needs to move along the tape to reach the next character. The ’previous character’ starts at 0, but is preserved throughout the entire program, even from one WRITE IN to the next.

Character-based output uses a similar model, but conceptually the output device moves on the inside of the tape, rather than on the outside. Therefore, the character that is actually output is the bit-reversal of the difference between the last character output before it was bit-reversed and the number found in the array (subtracting in that order, and adding 256 if the result is negative). (Rather than trying to parse the previous sentence, you may find it easier to look either at the source code to the compiler if you have it (the relevant part is binout in src/cesspool.c) or at some example C-INTERCAL programs that do text-based I/O.)


Next: , Previous: , Up: READ OUT and WRITE IN   [Index]