Mercurial > repo
comparison interps/clc-intercal/CLC-INTERCAL-Docs-1.-94.-2/doc/html/input_output.html @ 996:859f9b4339e6
<Gregor> tar xf egobot.tar.xz
author | HackBot |
---|---|
date | Sun, 09 Dec 2012 19:30:08 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
995:6883f5911eb7 | 996:859f9b4339e6 |
---|---|
1 <HTML> | |
2 <HEAD> | |
3 <TITLE>CLC-INTERCAL Reference</TITLE> | |
4 </HEAD> | |
5 <BODY> | |
6 <H1>CLC-INTERCAL Reference</H1> | |
7 <H2>... Input/Output</H2> | |
8 | |
9 <P> | |
10 We agree with the designers of C-INTERCAL that the I/O capabilities of | |
11 INTERCAL-72 are insufficient. However, we don't agree with their implementation | |
12 so we shamelessly go and do something entirely incompatible. However, if you | |
13 select the <I>ick</I> compiler for CLC-INTERCAL you get back their I/O behaviour. | |
14 </P> | |
15 | |
16 <P> | |
17 Table of contents: | |
18 <UL> | |
19 <LI><A HREF="index.html">Parent directory</A> | |
20 <LI><A HREF="#numeric">Numeric I/O</A> | |
21 <LI><A HREF="#alphanumeric">Alphanumeric I/O</A> | |
22 <LI><A HREF="#binary">Binary I/O</A> | |
23 <LI><A HREF="#class">Class I/O</A> | |
24 </UL> | |
25 </P> | |
26 | |
27 <H2><A NAME="numeric">Numeric I/O</A></H2> | |
28 | |
29 <P> | |
30 This is the standard INTERCAL-72 I/O. It is used with numeric variables | |
31 (one spot or two spots). | |
32 </P> | |
33 | |
34 <P> | |
35 On input, one line is read and its contents must be a sequence of digits | |
36 spelled out in full in a selection or popular languages, for example | |
37 "ONE THREE TWO ONE ZERO" (English for 13210) or "COIG CEITHIR TRI" (Scottish | |
38 Gaelic for 543). Spaces between digits are ignored. | |
39 </P> | |
40 | |
41 <P> | |
42 On output, butchered Roman numerals are used. However, we differ from | |
43 INTERCAL-72 slightly in that we use backslashes before numerals to multiply | |
44 them by 1,000,000 - however the actual format of the Roman numerals is | |
45 controlled by the compiler you use: if it is <I>sick</I>, you get the | |
46 backslashes; if it is <I>ick</I> or <I>1972</I>, you get the overline | |
47 like C-INTERCAL does; you can also write your own compiler (or modify | |
48 an existing one) and have another one of the seven or eight formats available. | |
49 </P> | |
50 | |
51 <P> | |
52 For example, 1,234,567,890 is written | |
53 <PRE> | |
54 \M\C\C\X\X\X\I\VdlxviiDCCCXC | |
55 </PRE> | |
56 by a program compiled with <I>sick</I> or | |
57 <PRE> | |
58 ________ | |
59 MCCXXXIVdlxviiDCCCXC | |
60 </PRE> | |
61 by a program compiled with <I>ick</I>. | |
62 </P> | |
63 | |
64 <H2><A NAME="alphanumeric">Alphanumeric I/O</A></H2> | |
65 | |
66 <P> | |
67 This is the kind of input/output the compiler itself uses to read the program | |
68 source and produce program listings. It applies to 16 bit arrays (tails), | |
69 which must be dimensioned. Multidimensional arrays are "flattened". | |
70 </P> | |
71 | |
72 <P> | |
73 On input, text is obtained from the next line, and it is converted to | |
74 an extended Baudot code. This is essentially the same as standard Baudot, | |
75 except that selecting "letters" when you are already in "letters" will cause | |
76 a shift to lowercase, and selecting "figures" when you are already in | |
77 "figures" causes a shift to other symbols. See <A HREF="charset.html">the | |
78 chapter on Character Sets</A> for a complete description of extended Baudot. | |
79 Please note that the insertion of shift codes means that the Baudot code | |
80 can be as much as three times as long as the original ASCII, so you must | |
81 dimension your array accordingly. | |
82 </P> | |
83 | |
84 <P> | |
85 On output, extended Baudot is converted to ASCII and sent to the virtual | |
86 line printer. | |
87 </P> | |
88 | |
89 <H2><A NAME="binary">Binary I/O</A></H2> | |
90 | |
91 <P> | |
92 This is the simplest, yet most powerful, form of input/output. It applies | |
93 to 32 bit arrays, which must be dimensioned. Multidimensional arrays are | |
94 "flattened". | |
95 </P> | |
96 | |
97 <P> | |
98 The input is assumed to be a stream of bytes, which is not interpreted in | |
99 any way. The number of bytes written in from the input is the same as the | |
100 size of the array specified. To compute the data to store in the array, a | |
101 simple algorithm is applied to every pair of consecutive elements. Since | |
102 this would give one less element, a #172 is inserted at the start. If the | |
103 two numbers in a pair are in <CODE>.1</CODE> (left) and <CODE>.2</CODE> | |
104 (right), the following fragment produces the value to be stored and leaves | |
105 it in <CODE>:1</CODE> | |
106 <PRE> | |
107 DO :1 <- '.2~.1'¢"'"¥'#65535¢.2'"~"#0¢#65535"'~'"¥'#65535¢.1'"~"#0¢#65535"'" | |
108 </PRE> | |
109 </P> | |
110 | |
111 <P> | |
112 We know it's an insult to the reader's intelligence to explain what it does, | |
113 but maybe somebody is in a hurry and doesn't have the two milliseconds to parse | |
114 that, so here it goes: the result is obtained by computing two numbers and | |
115 interleaving them. The first number computed is the second input element | |
116 selected by the first input element (<CODE>.2~.1</CODE>). The second number | |
117 computed is the same selection but applied to the bit-complement of the two | |
118 input numbers. Before applying the algorithm, the numbers are extended from | |
119 8 to 16 bits by padding them with a random value. It is clear that the result | |
120 has all the bits of the corresponding input value, permuted in a predictable | |
121 order, so all the information is there. | |
122 </P> | |
123 | |
124 <P> | |
125 A value of zero is inserted to indicate end-of-file. The padding is guaranteed | |
126 to have at least one bit set, so the values stored for any input value is never | |
127 zero. | |
128 </P> | |
129 | |
130 <P> | |
131 For output, the same algorithm is applied in reverse, except that zeros are | |
132 skipped. If you need to use a value zero, pad it to 32 bits with ones. The | |
133 current implementation does not check that the padding is sufficiently random, | |
134 although this might well change in future. | |
135 </P> | |
136 | |
137 <H2><A NAME="class">Class I/O</A></H2> | |
138 | |
139 <P> | |
140 If you use a class name (for example, <CODE>@1</CODE>) for I/O, nothing gets | |
141 actually input or output by the class. However, class registers have associated | |
142 filehandles and mentioning the class instructs the runtime to use the filehandle | |
143 on the current WRITE IN or READ OUT statement. For example: | |
144 <PRE> | |
145 DO READ OUT .1 + @3 + .2 + @2 + .3 | |
146 </PRE> | |
147 produces the value of .1 on the standard read filehandle (the default | |
148 filehandle for READ OUT), then the value of .2 on the standard splat# | |
149 filehandle (@3), finally .3 back on the standard read (@2). | |
150 </P> | |
151 | |
152 <P> | |
153 The runtime system predefines a small number of filehandles: | |
154 <UL> | |
155 <LI>@1 - standard write; the default for WRITE IN | |
156 <LI>@2 - standard read; the default for READ OUT | |
157 <LI>@3 - standard splat; error messages go here | |
158 <LI>@7 - null filehandle; if used in WRITE IN, always | |
159 returns an end-of-file condition; if used in READ OUT, | |
160 discards anything you send to it | |
161 <LI>@9 - trace filehandle; this is only available if | |
162 tracing is enabled | |
163 </UL> | |
164 </P> | |
165 | |
166 <P> | |
167 When running as a standalone program, or from inside the command-line | |
168 compiler tool, @1 corresponds to the system standard input, @2 | |
169 to the system standard output and @3 to the system standard error; | |
170 if tracing is enabled, @9 corresponds to the standard error, unless | |
171 the user has specified <I>--stdtrace=FILE</I> on the command line, | |
172 in which case @9 refers to that file. | |
173 </P> | |
174 | |
175 <P> | |
176 When running inside the calculator, these filehandles are mapped to | |
177 something appropriate for the user interface in use. Usually, @2 | |
178 and @3 send their output to the calculator's display, @9 stores the | |
179 output separately (use the "trace" entry from the "Windows" menu to | |
180 see it) and @1 causes a dialog to pop up and asking the user to type | |
181 something. | |
182 </P> | |
183 | |
184 <P> | |
185 The <A HREF="syscall.html">system call interface</A> allows to | |
186 open files and TCP sockets and associate them with filehandles. | |
187 </P> | |
188 | |
189 <P> | |
190 Note that if a program steals a class register from another program, | |
191 it will use the corresponding filehandle as well. | |
192 </P> | |
193 | |
194 </BODY> | |
195 </HTML> |