INTERCAL is a programming language like no other. This is good, or at least, it is good that other languages are as unlike INTERCAL as possible. This page is a showcase, or freak show, of INTERCAL source code. A distribution including the reference manual by Woods and Lyon, and Eric Raymond's C-INTERCAL compiler, is available from The Retrocomputing Museum. Text files of the original manual and the supplemental manual describing additional features of the C-INTERCAL compiler are available at
while Brian Raiter has put up an HTML version of the combined manual and a new INTERCAL Resources page.
Little code has ever been written in INTERCAL, most wimps being content to just read the manual, so it will be interesting to see what new and horrible things can yet be accomplished with the language. There are some sources on this page not available with the standard distribution, and more are welcome. You could send them to me, but it might be better to post to alt.lang.intercal and try to get some traffic going there again.
This routine raises .1
to the .2
power,
returning the result in :1
. When called through
(2040)
it dies with an error message on overflow. When
called through (2049)
it returns #2
in
.4
on overflow, otherwise .4
is set
to #1
.
This was one of the programming suggestions from the original manual. Of the others, the sorting routine, the prime number table, and a program to compute pi have been done. The remaining suggestions are to write a floating point library and an FFT.
[If you see garbage below, either your browser cannot handle the table or I've botched something up. You can get this exponentiation routine as part of the powers program, and there is a link to a more efficient version farther down.]
(2040) PLEASE STASH .4 DO ABSTAIN FROM (2047) (2049) DO STASH .1 + .2 + :2 + :3 + :4 + :5 + :6 PLEASE DO .4 <- #1 DO :5 <- .1 DO :6 <- #1 |
Initialization for both entry points. |
DO (2044) NEXT |
We will return to this point when the computation is finished. |
(2047) DO (2048) NEXT DO .1 <- .4 DO (2046) NEXT DO (1999) NEXT (2046) DO (2042) NEXT PLEASE REINSTATE (2047) PLEASE RETRIEVE .4 |
This section causes an error on overflow, if enabled. (1999)
is an error statement in the standard library.
|
(2048) DO :1 <- :6 DO RETRIEVE .1 + .2 + :2 + :3 + :4 + :5 + :6 PLEASE RESUME #2 |
Clean up and return. |
(2044) DO (2045) NEXT (2045) PLEASE FORGET #1 |
Top of main loop. |
DO .1 <- "?!2~#1'$#1"~#3 DO (2041) NEXT PLEASE DO :1 <- :6 PLEASE DO :2 <- :5 DO (1549) NEXT DO :6 <- :3 DO .4 <- '?"'V.4$":4~#3"'~#4"$#1'~#3 DO (2043) NEXT (2042) PLEASE RESUME .1 (2041) DO (2042) NEXT (2043) PLEASE FORGET #1 |
At this point, :5 contains .1 raised to the power
of a power of 2. If the corresponding bit in .2 is set, we use
the (1549) multiplication routine in the standard library to
multiply in into the result accumulator :6 .
|
DO .2 <- .2~#65534 |
Shift .2 to the right to bring the next bit into position.
|
DO .1 <- '?"!2~.2'~#1"$#2'~#3 DO (2042) NEXT PLEASE DO :1 <- :5 PLEASE DO :2 <- :5 DO (1549) NEXT DO :5 <- :3 DO .4 <- '?"'V.4$":4~#3"'~#4"$#1'~#3 |
If .2 is now #0 ,
return to clean up section, otherwise square
the quantity in :5 and go through the main loop again.
|
DO (2045) NEXT |
Bottom of main loop. |
COME FROM
statements have been avoided so that this could
be a library routine called from "standard" INTERCAL programs.
The expressions '?"'V.4$":4~#3"'~#4"$#1'~#3
preserve the
overflow flags. .4
and :4
are either
#1
or #2
, and these expressions return
#2
if either of the inputs are #2
.
The version in the
supplemental library has some enhancements over
this one. The overflow accumulation is simplified, setting .4
to #1
on overflow or #0
otherwise during the loop
and then converting it to #2
or #1
when ready to
return. Also, one or more multiplications are eliminated by checking that
:6
is at least #2
before multiplying it by
:5
. I have not investigated whether it
might be more efficient to return or terminate immediately after the
first overflow, instead of working through the entire exponent.
.1
(for those of you not yet fluent in
INTERCAL, note that .1
is a variable).[Hit Counter]
On August 9, 1996 this page was selected Geek Site of the Day.
Maintainer: Louis Howell