"If any one of them can explain it," said Alice, "I'll give him
sixpence. I don't believe there's an atom of meaning in it."
The jury all wrote down, on their slates, "She doesn't
believe there's an atom of meaning in it," but none of them
attempted to explain the paper.
"If there's no meaning in it," said the King, "that saves a world of
trouble, you know, as we needn't try to find any. And yet, I don't
know," he went on, spreading out the verses on one knee, and looking
at them with one eye: "I seem to see some meaning in them, after
all...."
For the user looking to become more familiar with the INTERCAL language, we present in this section an analysis of a complex program, as well as some suggested projects for the ambitious programmer.
Considering the effort involved in writing an INTERCAL program, it was decided in putting together this manual to use an already existing program for instructive analysis. Since there was only one such program available, we have proceeded to use it. It is known as the "INTERCAL System Library".
The program listing is in section 8.3. It is in the same format as would be produced by the Princeton INTERCAL compiler in FORMAT mode with WIDTH=62 (see section 12). For a description of the functions performed by the Library, see section 7.2.
We shall not attempt to discuss here the algorithms used, but rather we shall point out some of the general techniques applicable to a wide range of problems.
Statements 10, 14,
15, and 26 make up a virtual
"computed GO TO". When statement 10
is executed, control passes eventually to statement
16 or 11, depending on whether
.5 contains #1 or #2,
respectively. The value of .5 is determined in statement
9, which demonstrates another handy technique. To
turn an expression, exp, with value #0 or
#1, into #1 or #2 (for use in a
GO TO), use "?'exp'$#1"~#3. To reverse the
condition (i.e., convert #0 to #2 and leave
#1 alone) use "?'exp'$#2"~#3.
Certain conditions are easily checked. For example, to test for zero, select the value from itself and select the bottom bit (see statement 54). To test for all bits being 1's, select the value from itself and select the top bit. The test for greater than, performed in statements 219 and 220 on 32-bit values, employs binary logical operations, which are performed as follows:
'?.1$.2'~'#0$#65535'
for 16-bit values or, for 32-bit values:
"'?":1~'#65535$30'"$":2~'#65535$#0'"'~'#0
$#65535'"$"'?":1~'#0$#65535'"$":2~'#0
$#65535'"'~'#0$#65535'"
(The proofs are left as an exercise to the reader.)
Testing for greater-than with 16-bit values is somewhat simpler and is done with the pair of statements:
DO .C <- '?.Ac.B'~'#0$#65535'
DO .C <- '&"'.A~.C'~'"?'?.C~.C'$#32768"
~"#0$#65535"'"$".C~.C"'~#1
This sets .C (a dummy variable) to
#1 if .A >
.B, and #0 otherwise. The
expression may be expanded as described above to instead set
.C to #1 or #2.
Note also in statement 220 the occurrence of
~"#65535$#65535". Although these operations select the
entire value, they are not extraneous, as they ensure that the
forthcoming ?s will be operating on 32-bit values.
(However, see section 3.4.1.1.)
In several virtual computed GO TOs the DO FORGET
#1 (statement 15 in the earlier example) has
been omitted, since the next transfer of control would be a DO
RESUME #1. By making this a DO RESUME #2 instead,
the FORGET may be forgotten.
In statement 64, note that .2 is
STASHed twice by a single statement. This is perfectly
legal.
Lastly, note in statements 243 and 214 respectively, expressions for shifting 16- and 32-bit variables logically one place to the left. Statement 231 demonstrates right-shifting for 32-bit variables.
1 (1000) PLEASE IGNORE .4
2 PLEASE ABSTAIN FROM (1005)
3 (1009) DO STASH .1 + .2 + .5 + .6
4 DO .4 <- #1
5 DO (1004) NEXT
6 (1004) PLEASE FORGET #1
7 DO .3 <- '?.1$.2'~'#0$#65535'
8 DO .6 <- '&.1$.2'~'#0$#65535'
9 PLEASE DO .5 <- "?!6~#32768'$#1"~#3
10 DO (1002) NEXT
11 DO .4 <- #2
12 (1005) DO (1006) NEXT
* 13 (1999) DOUBLE OR SINGLE PRECISION OVERFLOW
14 (1002) DO (1001) NEXT
15 (1006) PLEASE FORGET #1
16 DO .5 <- '?"!6~.6'~#1"$#1'~#3
17 DO (1003) NEXT
18 DO .1 <- .3
19 DO .2 <- !6$#0'~'#32767$#1'
20 DO (1004) NEXT
21 (1003) DO (1001) NEXT
22 DO REINSTATE (1005)
23 (1007) PLEASE RETRIEVE .1 + .2 + .5 + .6
24 DO REMEMBER .4
25 PLEASE RESUME #2
26 (1001) DO RESUME .5
27 (1010) DO STASH .1 + .2 + .4
28 DO .4 <- .1
29 DO .1 <- '?.2$#65535'~'#0$#65535'
30 DO (1020) NEXT
31 PLEASE DO .2 <- .4
32 PLEASE DO (1009) NEXT
33 DO RETRIEVE .1 + .2 + .4
34 PLEASE RESUME #1
35 (1020) DO STASH .2 + .3
36 DO .2 <- #1
37 PLEASE DO (1021) NEXT
38 (1021) DO FORGET #1
39 DO .3 <- "?!1~.2'$#1"~#3
40 PLEASE DO .1 <- '?.1$.2'~'#0$#65535'
41 DO (1022) NEXT
42 DO .2 <- !2$#0'~'#32767$#1'
43 DO (1021) NEXT
44 (1023) PLEASE RESUME .3
45 (1022) DO (1023) NEXT
46 PLEASE RETRIEVE .2 + .3
47 PLEASE RESUME #2
48 (1030) DO ABSTAIN FROM (1033)
49 PLEASE ABSTAIN FROM (1032)
50 (1039) DO STASH :1 + .5
51 DO (1530) NEXT
52 DO .3 <- :1~#65535
53 PLEASE DO .5 <- :1~'#65280$#65280'
54 DO .5 <- '?"!5~.5'~#1"$#1'~#3
55 DO (1031) NEXT
56 (1032) DO (1033) NEXT
57 DO (1999) NEXT
58 (1031) DO (1001) NEXT
59 (1033) DO .4 <- .5
60 DO REINSTATE (1032)
61 PLEASE REINSTATE (1033)
62 DO RETRIEVE :1 + .5
63 PLEASE RESUME #2
64 (1040) PLEASE STASH .1 + .2 + .2 + :1 + :2 + :3
65 DO .2 <- #0
66 DO (1520) NEXT
67 DO STASH :1
68 PLEASE RETRIEVE .2
69 DO .1 <- .2
70 DO .2 <- #0
71 PLEASE DO (1520) NEXT
72 DO :2 <- :1
73 DO RETRIEVE .1 + .2 + :1
74 DO (1550) NEXT
75 PLEASE DO .3 <- :3
76 DO RETRIEVE :1 + :2 + :3
77 DO RESUME #1
78 (1050) PLEASE STASH :2 + :3 + .5
79 DO :2 <- .1
80 PLEASE DO (1550) NEXT
81 DO .5 <- :3~'#65280$#65280'
82 DO .5 <- '?"!5~.5'~#1"$#1'~#3
83 DO (1051) NEXT
84 DO (1999) NEXT
85 (1051) DO (1001) NEXT
86 DO .2 <- :3
87 PLEASE RETRIEVE :2 + :3 + .5
88 DO RESUME #2
89 (1500) PLEASE ABSTAIN FROM (1502)
90 PLEASE ABSTAIN FROM (1506)
91 (1509) PLEASE STASH :1 + .1 + .2 + .3 + .4 + .5 + .6
92 DO .1 <- :1~#65535
93 PLEASE DO .2 <- :2~#65535
94 DO (1009) NEXT
95 DO .5 <- .3
96 PLEASE DO .6 <- .4
97 DO .1 <- :1~'#65280$#65280'
98 DO .2 <- :2~'#65280$#65280'
99 DO (1009) NEXT
100 DO .1 <- .3
101 PLEASE DO (1503) NEXT
102 DO .6 <- .4
103 DO .2 <- #1
104 DO (1009) NEXT
105 DO .1 <- .3
106 DO (1501) NEXT
107 (1504) PLEASE RESUME .6
108 (1503) DO (1504) NEXT
109 (1501) DO .2 <- .5
110 DO .5 <- '?"'&.6$.4'~#1"$#2'~#3
111 DO (1505) NEXT
112 (1506) DO (1502) NEXT
113 PLEASE DO (1999) NEXT
114 (1505) DO (1001) NEXT
115 (1502) DO :4 <- .5
116 DO (1520) NEXT
117 DO :3 <- :1
118 PLEASE RETRIEVE :1 + .1 + .2 + .3 + .4 + .5 + .6
119 DO REINSTATE (1502)
120 DO REINSTATE (1506)
121 PLEASE RESUME #3
122 (1510) DO STASH :1 + :2 + :4
123 DO :1 <- "'?":2~'#65535$#0'"$#65535'~'#0$#6553
5'"$"'?":2~'#0$#65535'"$#65535'~'#0$#65535
'"
124 DO :2 <- #1
125 DO (1509) NEXT
126 PLEASE RETRIEVE :1
127 DO :2 <- :3
128 PLEASE DO (1509) NEXT
129 DO RETRIEVE :2 + :4
130 PLEASE RESUME #1
131 (1520) PLEASE STASH .3 + .4
132 DO .3 <- .1~#43690
133 DO (1525) NEXT
134 PLEASE DO .4 <- 'V.3$".2~#43690"'~'#0$#65535'
135 DO .3 <- .1~#21845
136 PLEASE DO (1525) NEXT
137 DO :1 <- .4$"'V.3$".2~#21845"'~'#0$#65535'"
138 PLEASE RETRIEVE .3 + .4
139 DO RESUME #1
140 (1525) DO .3 <- '"'"'"!3$#0'~'#32767$#1'"$#0'~'#32767
$#1'"$#0'~'#16383$#3'"$#0'~'#4095$#15'
141 PLEASE RESUME #1
142 (1530) DO STASH :2 + :3 + .3 + .5
143 DO :1 <- #0
144 DO :2 <- .2
145 DO .3 <- #1
146 DO (1535) NEXT
147 (1535) PLEASE FORGET #1
148 DO .5 <- "?!1~.3'$#1"~#3
149 DO (1531) NEXT
150 DO (1500) NEXT
151 DO :1 <- :3
152 PLEASE DO (1533) NEXT
153 (1531) PLEASE DO (1001) NEXT
154 (1533) DO FORGET #1
155 DO .3 <- !3$#0'~'#32767$#1'
156 DO :2 <- ":2~'#0$#65535'"$"'":2~'#32767$#0'"$#
0'~'#32767$#1'"
157 PLEASE DO .5 <- "?!3~.3'$#1"~#3
158 DO (1532) NEXT
159 DO (1535) NEXT
160 (1532) DO (1001) NEXT
161 PLEASE RETRIEVE :2 + :3 + .3 + .5
162 DO RESUME #2
163 (1540) PLEASE ABSTAIN FROM (1541)
164 DO ABSTAIN FROM (1542)
165 (1549) PLEASE STASH :1 + :2 + :4 + :5 + .1 + .2 + .5
166 DO .1 <- :1~#65535
167 PLEASE DO .2 <- :2~'#65280$#65280'
168 DO .5 <- :1~'#65280$#65280'
169 DO (1530) NEXT
170 DO :3 <- :1
171 DO .2 <- :2~#65535
172 PLEASE DO (1530) NEXT
173 DO :5 <- :1
174 DO .1 <- .5
175 DO (1530) NEXT
176 DO :4 <- :1
177 PLEASE DO :1 <- ":3~'#65280$#65280'"$":5~'#652
80$#65280'"
178 DO .5 <- ':1~:1'~#1
179 DO .2 <- :2~'#65280$#65280'
180 DO (1530) NEXT
181 PLEASE DO .5 <- '"':1~:1'~#1"$.5'~#3
182 DO .1 <- :3~#65535
183 DO .2 <- #0
184 DO (1520) NEXT
185 PLEASE DO :2 <- :1
186 PLEASE DO .1 <- :4~#65535
187 DO (1520) NEXT
188 DO (1509) NEXT
189 DO .5 <- !5$":4~#3"'~#15
190 DO :1 <- :3
191 DO :2 <- :5
192 DO (1509) NEXT
193 PLEASE DO .5 <- !5$":4~#3"'~#63
194 DO .5 <- '?"!5~.5'~#1"$#1'~#3
195 PLEASE RETRIEVE :4
196 (1541) DO :4 <- .5
197 DO (1543) NEXT
198 (1542) DO (1544) NEXT
199 PLEASE DO (1999) NEXT
200 (1543) DO (1001) NEXT
201 (1544) DO REINSTATE (1541)
202 PLEASE REINSTATE (1542)
203 PLEASE RETRIEVE :1 + :2 + :5 + .1 + .2 + .5
204 DO RESUME #2
205 (1550) DO STASH :1 + :4 + :5 + .5
206 DO :3 <- #0
207 DO .5 <- '?"':2~:2'~#1"$#1'~#3
208 PLEASE DO (1551) NEXT
209 DO :4 <- #1
210 PLEASE DO (1553) NEXT
211 (1553) DO FORGET #1
212 DO .5 <- '?":2~'#32768$#0'"$#2'~#3
213 DO (1552) NEXT
214 DO :2 <- ":2~'#0$#65535'"$"'":2~'#32767$#0'"$#
0'~'#32767$#1'"
215 PLEASE DO :4 <- ":4~'#0$#65535'"$"'":4~'#32767
$#0'"$#0'~'#32767$#1'"
216 DO (1553) NEXT
217 (1552) DO (1001) NEXT
218 (1556) PLEASE FORGET #1
219 DO :5 <- "'?":1~'#65535$#0'"$":2~'#65535$#0'"'
~'#0$#65535'"$"'?":1~'#0$#65535'"$":2~'#0$
#65535'"'~'#0$#65535'"
220 DO .5 <- '?"'&"':2~:5'~'"'?"'?":5~:5"~"#65535~
#65535"'~'#65535$#0'"$#32768'~'#0$#65535'"
$"'?":5~:5"~"#65535$#65535"'~'#0$#65535'"'
"$"':5~:5'~#1"'~#1"$#2'~#3
221 DO (1554) NEXT
222 DO :5 <- :3
223 DO (1510) NEXT
224 PLEASE DO :1 <- :3
225 DO :3 <- "'V":4~'#65535$#0'"$":5~'#65535$#0'"'
~'#0$#65535'"$"'V":4~'#0$#65535'"$":5~'#0$
#65535'"'~'#0$#65535'"
226 DO (1555) NEXT
227 (1554) PLEASE DO (1001) NEXT
228 (1555) DO FORGET #1
229 DO .5 <- "?':4~#1'$#2"~#3
230 DO (1551) NEXT
231 DO :2 <- ":2~'#0$#65534'"$":2~'#65535$#0'"
232 DO :4 <- ":4~'#0$#65534'"$":4~'#65535$#0'"
233 PLEASE DO (1556) NEXT
234 (1551) DO (1001) NEXT
235 PLEASE RETRIEVE :1 + :4 + :5 + .5
236 PLEASE RESUME #2
237 (1900) DO STASH .2 + .3 + .5
238 DO .1 <- #0
239 DO .2 <- #1
240 PLEASE DO (1901) NEXT
241 (1901) DO FORGET #1
242 DO %50 .1 <- 'V.1$.2'~'#0$#65535'
243 DO .2 <- !2$#0'~'#32767$#1'
244 PLEASE DO .5 <- "?!2~.2'$#1"~#3
245 DO (1902) NEXT
246 DO (1901) NEXT
247 (1902) DO (1001) NEXT
248 DO RETRIEVE .2 + .3 + .5
249 PLEASE RESUME #2
250 (1910) PLEASE STASH .1 + .3 + .5 + :1 + :2 + :3
251 DO .3 <- #65524
252 DO :1 <- #6
253 DO (1911) NEXT
* 254 PLEASE NOTE THAT YOU CAN'T GET THERE FROM HERE
255 (1912) DO (1001) NEXT
256 (1911) DO FORGET #1
257 PLEASE DO (1900) NEXT
258 DO :2 <- .1
259 DO (1500) NEXT
260 PLEASE DO :1 <- :3
261 DO .1 <- .3
262 DO (1020) NEXT
263 PLEASE DO .3 <- .1
264 DO .5 <- '?"!3~.3'~#1"$#2'~#3
265 DO (1912) NEXT
266 DO .1 <- #12
267 PLEASE DO (1050) NEXT
268 DO RETRIEVE .1
269 DO (1530) NEXT
270 DO :2 <- #32768
271 DO (1500) NEXT
272 PLEASE DO .2 <- :3~'#65280$#65280'
273 PLEASE RETRIEVE .3 + .5 + :1 + :2 + :3
274 DO RESUME #1
For the novice INTERCAL programmer, we provide here a list of suggested INTERCAL programming projects:
Write an integer exponentiation subroutine. :1
<- .1 raised to the .2
power.
Write a double-precision sorting subroutine. Given 32-bit array
;1 of size :1, sort the contents into
numerically increasing order, leaving the results in ;1.
Generate a table of prime numbers.
Put together a floating-point library, using 32-bit variables to represent floating-point numbers (let the upper half be the mantissa and the lower half be the characteristic). The library should be capable of performing floating-point addition, subtraction, multiplication, and division, as well as the natural logarithm function.
Program a Fast Fourier Transform (FFT). This project would probably entail the writing of the floating-point library as well as sine and cosine functions.
Calculate, to :1 places, the value of pi.
(Working programs for each of these projects are included in the C-INTERCAL distribution's pit directory of sample code.)