INTERCAL
Encyclopedia
INTERCAL, a programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 parody, is an esoteric programming language
Esoteric programming language
An esoteric programming language is a programming language designed as a test of the boundaries of computer programming language design, as a proof of concept, or as a joke...

 that was created by Don Woods and James M. Lyon
James M. Lyon
James M. Lyon is an American perennial hacker and computer programmer. Jim teamed with Don Woods while both were attending Princeton in 1972 to produce the unprecedented, excursive INTERCAL programming language...

, two Princeton University
Princeton University
Princeton University is a private research university located in Princeton, New Jersey, United States. The school is one of the eight universities of the Ivy League, and is one of the nine Colonial Colleges founded before the American Revolution....

 students, in 1972. It satirizes aspects of the various programming languages at the time, as well as the proliferation of proposed language constructs and notations in the 1960s. Consequently, the humor may appear rather dated to modern readers brought up with C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 or Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

.

According to the original manual by the authors,
There are two currently maintained versions of INTERCAL: C-INTERCAL, formerly maintained by Eric S. Raymond
Eric S. Raymond
Eric Steven Raymond , often referred to as ESR, is an American computer programmer, author and open source software advocate. After the 1997 publication of The Cathedral and the Bazaar, Raymond was for a number of years frequently quoted as an unofficial spokesman for the open source movement...

, and CLC-INTERCAL, maintained by Claudio Calvelli.

Introduction

INTERCAL is intended to be completely different from all other computer languages. Common operations in other languages have cryptic and redundant syntax in INTERCAL. From the INTERCAL Reference Manual:
The INTERCAL Reference Manual contains many paradoxical, nonsensical, or otherwise humorous instructions (in the manner of the game Mornington Crescent
Mornington Crescent (game)
Mornington Crescent is a spoof game, featured in the BBC Radio 4 comedy panel show I'm Sorry I Haven't a Clue, which satirises complicated strategy games....

):
The manual also contains a "tonsil
Tonsil
Palatine tonsils, occasionally called the faucial tonsils, are the tonsils that can be seen on the left and right sides at the back of the throat....

", as explained in this footnote: "4) Since all other reference manuals have Appendices, it was decided that the INTERCAL manual should contain some other type of removable organ."

INTERCAL has many other features designed to make it even more aesthetically unpleasing to the programmer: it uses statements such as "READ OUT", "IGNORE", "FORGET", and modifiers such as "PLEASE". This last keyword provides two reasons for the program's rejection by the compiler: if "PLEASE" does not appear often enough, the program is considered insufficiently polite, and the error message says this; if too often, the program could be rejected as excessively polite. Although this feature existed in the original INTERCAL compiler, it was undocumented.

The INTERCAL manual gives unusual names to all non-alphanumeric ASCII
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

 characters: single and double quotes are "sparks" and "rabbit ears" respectively. (The exception is the ampersand
Ampersand
An ampersand is a logogram representing the conjunction word "and". The symbol is a ligature of the letters in et, Latin for "and".-Etymology:...

: as the Jargon File
Jargon File
The Jargon File is a glossary of computer programmer slang. The original Jargon File was a collection of terms from technical cultures such as the MIT AI Lab, the Stanford AI Lab and others of the old ARPANET AI/LISP/PDP-10 communities, including Bolt, Beranek and Newman, Carnegie Mellon...

 states, "what could be sillier?") The assignment operator, represented as an equals sign (INTERCAL's "half mesh") in many other programming languages, is in INTERCAL a left-arrow, "<-", referred to as "gets" and made up of an "angle" and a "worm".

The original Princeton implementation used punched card
Punched card
A punched card, punch card, IBM card, or Hollerith card is a piece of stiff paper that contains digital information represented by the presence or absence of holes in predefined positions...

s and the EBCDIC
EBCDIC
Extended Binary Coded Decimal Interchange Code is an 8-bit character encoding used mainly on IBM mainframe and IBM midrange computer operating systems....

 character set. To allow INTERCAL to run on computers using ASCII
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

, substitutions for two characters had to be made: $ substituted for ¢ as the mingle operator, "represent[ing] the increasing cost of software in relation to hardware", and ? was substituted for ∀ as the unary exclusive-or operator to "correctly express the average person's reaction on first encountering exclusive-or". In recent versions of C-INTERCAL, the older operators are supported as alternatives; INTERCAL programs may now be encoded in ASCII
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

, Latin-1, or UTF-8
UTF-8
UTF-8 is a multibyte character encoding for Unicode. Like UTF-16 and UTF-32, UTF-8 can represent every character in the Unicode character set. Unlike them, it is backward-compatible with ASCII and avoids the complications of endianness and byte order marks...

.

The Usenet
Usenet
Usenet is a worldwide distributed Internet discussion system. It developed from the general purpose UUCP architecture of the same name.Duke University graduate students Tom Truscott and Jim Ellis conceived the idea in 1979 and it was established in 1980...

 newsgroup alt.lang.intercal is devoted to the study and appreciation of INTERCAL and other esoteric languages.

Despite the language's intentionally obtuse and wordy syntax, INTERCAL is nevertheless Turing-complete: given enough memory, INTERCAL can solve any problem that a Universal Turing machine
Universal Turing machine
In computer science, a universal Turing machine is a Turing machine that can simulate an arbitrary Turing machine on arbitrary input. The universal machine essentially achieves this by reading both the description of the machine to be simulated as well as the input thereof from its own tape. Alan...

 can solve. Most implementations of INTERCAL do this very slowly, however. A Sieve of Eratosthenes
Sieve of Eratosthenes
In mathematics, the sieve of Eratosthenes , one of a number of prime number sieves, is a simple, ancient algorithm for finding all prime numbers up to a specified integer....

 benchmark, computing all prime numbers less than 65536, was tested on a Sun
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...

 SPARCStation-1. In C, it took less than half a second; the same program in INTERCAL took over seventeen hours.

It should be noted that almost any programming language allows notation
Notation
-Written communication:* Phonographic writing systems, by definition, use symbols to represent components of auditory language, i.e. speech, which in turn refers to things or ideas. The two main kinds of phonographic notational system are the alphabet and syllabary...

al horrors as great as or greater than INTERCAL's, as demonstrated in contests such as the International Obfuscated C Code Contest
International Obfuscated C Code Contest
The International Obfuscated C Code Contest is a programming contest for the most creatively obfuscated C code. It was held annually between 1984 and 1996, and thereafter in 1998, 2000, 2001, 2004, 2005 and 2006....

. However, these are generally intentional efforts to create unreadable code, in contrast to INTERCAL's design, which forces virtually all code to be unreadable.

According to the INTERCAL manual, "the aim in designing INTERCAL was to have no precedents", supposedly neither in flow control features, nor in data manipulation operators. The designers were relatively successful; however, one known precedent is a machine instruction in a Soviet mainframe computer BESM-6, released in 1967, that is effectively equivalent to INTERCAL's "select" operator.

Dialects

The original Woods–Lyon INTERCAL was very limited in its input/output
Input/output
In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world, possibly a human, or another information processing system. Inputs are the signals or data received by the system, and outputs are the signals or data sent from it...

 capabilities: the only acceptable input were numbers with the digits spelled out, and the only output was an extended version of Roman numerals
Roman numerals
The numeral system of ancient Rome, or Roman numerals, uses combinations of letters from the Latin alphabet to signify values. The numbers 1 to 10 can be expressed in Roman numerals as:...

. A while later, there was an 'Atari implementation', about which notes are provided in the INTERCAL reference manual; it 'differs from the original Princeton version primarily in the use of ASCII rather than EBCDIC'.

The C-INTERCAL reimplementation, being available on the Internet, has made the language more popular with devotees of esoteric programming languages. The C-INTERCAL dialect has a few differences from original INTERCAL and introduced a few new features, such as a COME FROM
COMEFROM
In computer programming, COMEFROM is an obscure control flow structure used in some programming languages, originally as a joke....

 statement and a means of doing text I/O based on the Turing Text Model.

The authors of C-INTERCAL also created the TriINTERCAL variant, based on the Ternary numeral system
Ternary numeral system
Ternary is the base- numeral system. Analogous to a bit, a ternary digit is a trit . One trit contains \log_2 3 bits of information...

 and generalizing INTERCAL's set of operators.

A more recent variant is Threaded Intercal, which extends the functionality of COME FROM to support multithreading
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...

.

Data structures

INTERCAL-72 (the original version of INTERCAL) had only four data type
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...

s, the 16-bit
Bit
A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...

 integer
Integer
The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...

 (represented with a ., called a 'spot'), the 32-bit integer (:, a 'twospot'), the array
Array data type
In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

 of 16-bit integers (,, a 'tail'), and the array of 32-bit integers (;, a 'hybrid'). There are 65535 available variables of each type, numbered from .1 to .65535 for 16-bit integers, for instance. However, each of these variables has its own stack
Stack (data structure)
In computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack,...

 on which it can be pushed and popped (STASHed and RETRIEVEd, in INTERCAL terminology), increasing the possible complexity of data structures. (More modern versions of INTERCAL have by and large kept the same data structures, with appropriate modifications; TriINTERCAL, which modifies the radix
Radix
In mathematical numeral systems, the base or radix for the simplest case is the number of unique digits, including zero, that a positional numeral system uses to represent numbers. For example, for the decimal system the radix is ten, because it uses the ten digits from 0 through 9.In any numeral...

 with which numbers are represented, can use a 10-trit type rather than a 16-bit type, and CLC-INTERCAL implements many of its own data structures, such as 'classes and lectures', by making the basic data types store more information rather than adding new types.) Arrays are dimensioned by assigning to them as if they were a scalar
Scalar (computing)
In computing, a scalar variable or field is one that can hold only one value at a time; as opposed to composite variables like array, list, hash, record, etc. In some contexts, a scalar value may be understood to be numeric. A scalar data type is the type of a scalar variable...

 variable. Constants can also be used, and are represented by a # ('mesh') followed by the constant itself, written as a decimal
Decimal
The decimal numeral system has ten as its base. It is the numerical base most widely used by modern civilizations....

 number; only integer constants from 0 to 65535 are supported.

Operators

There are only five operators in INTERCAL-72; implementations vary in which characters represent which operation, and many accept more than one character, so more than one possibility is given for many of the operators.

Sources for this table:
Operator INTERCAL-72 characters Atari characters C-INTERCAL characters CLC-INTERCAL characters
INTERLEAVE / MINGLE c backspace
Backspace
Backspace is the keyboard key that originally pushed the typewriter carriage one position backwards, and in modern computer displays moves the cursor one position backwards, deletes the preceding character, and shifts back the text after it by one position....

 /
$ ¢, $, c backspace / ¢
SELECT ~ ~ ~ ~
AND & & & &
OR V V V V
XOR V backspace - ? V backspace -, ?, V backspace -, ¥

Contrary to most other languages, AND, OR, and XOR are unary
Unary operation
In mathematics, a unary operation is an operation with only one operand, i.e. a single input. Specifically, it is a functionf:\ A\to Awhere A is a set. In this case f is called a unary operation on A....

 operators, which work on consecutive bits of their argument; the most significant bit
Most significant bit
In computing, the most significant bit is the bit position in a binary number having the greatest value...

 of the result is the operator applied to the most significant and least significant bits of the input, the second-most-significant bit of the result is the operator applied to the most and second-most significant bits, the third-most-significant bit of the result is the operator applied to the second-most and third-most bits, and so on. The operator is placed between the punctuation mark specifying a variable name or constant and the number that specifies which variable it is, or just inside grouping marks (i.e. one character later than it would be in programming languages like C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

.) SELECT and INTERLEAVE (which is also known as MINGLE) are infix binary operators; SELECT takes the bits of its first operand that correspond to '1' bits of its second operand and removes the bits that correspond to '0' bits, shifting towards the least significant bit and padding with zeroes (so 51 (110011 in binary) SELECT 21 (10101 in binary) is 5 (101 in binary)); MINGLE alternates bits from its first and second operands (in such a way that the least significant bit of its second operand is the least significant bit of the result). There is no operator precedence; grouping marks must be used to disambiguate the precedence where it would otherwise be ambiguous (the grouping marks available are ' ('spark'), which matches another spark, and " ('rabbit ears'), which matches another rabbit ears; the programmer is responsible for using these in such a way that they make the expression unambiguous.)

Control structures

INTERCAL statements all start with a 'statement identifier'; in INTERCAL-72, this can be DO, PLEASE, or PLEASE DO, all of which mean the same to the program (but using one of these too heavily causes the program to be rejected, an undocumented feature
Undocumented feature
Undocumented features are frequently found in computer software releases. Sometimes the documentation is omitted through simple oversight, but undocumented features are often elements of the software not intended for use by end users, but left available for use by the vendor for software support...

 in INTERCAL-72 that was mentioned in the C-INTERCAL manual), or an inverted form (with NOT or N'T appended to the identifier). Backtracking INTERCAL, a modern variant, also allows variants using MAYBE (possibly combined with PLEASE or DO) as a statement identifier, which introduces a choice-point. Before the identifier, an optional line number (an integer enclosed in parentheses) can be given; after the identifier, a percent chance of the line executing can be given in the format %50, which defaults to 100%.

In INTERCAL-72, the main control structures are NEXT, RESUME, and FORGET. DO (line) NEXT branches to the line specified, remembering the next line that would be executed if it weren't for the NEXT on a call stack (other identifiers than DO can be used on any statement, DO is given as an example); DO FORGET expression removes expression entries from the top of the call stack (this is useful to avoid the error that otherwise happens when there are more than 80 entries), and DO RESUME expression removes expression entries from the call stack and jumps to the last line remembered.

C-INTERCAL also provides the COME FROM instruction, written DO COME FROM (line); CLC-INTERCAL and the most recent C-INTERCAL versions also provide computed COME FROM (DO COME FROM expression) and NEXT FROM, which is like COME FROM but also saves a return address on the NEXT STACK.

Alternative ways to affect program flow, originally available in INTERCAL-72, are to use the IGNORE and REMEMBER instructions on variables (which cause writes to the variable to be silently ignored and to take effect again, so that instructions can be disabled by causing them to have no effect), and the ABSTAIN and REINSTATE instructions on lines or on types of statement, causing the lines to have no effect or to have an effect again respectively.

Miscellaneous

Input (using the WRITE IN instruction) and output (using the READ OUT instruction) do not use the usual formats; in INTERCAL-72, WRITE IN inputs a number written out as digits in English (such as SIX FIVE FIVE THREE FIVE), and READ OUT outputs it in 'butchered' Roman numerals
Roman numerals
The numeral system of ancient Rome, or Roman numerals, uses combinations of letters from the Latin alphabet to signify values. The numbers 1 to 10 can be expressed in Roman numerals as:...

. More recent versions have their own I/O systems. Comments can be achieved by using the inverted statement identifiers involving NOT or N'T; these cause lines to be initially ABSTAINed so that they have no effect. (A line can be ABSTAINed from even if it doesn't have valid syntax; syntax errors happen at runtime, and only then when the line is un-ABSTAINed.)

Hello, world

The traditional "Hello, world!" program
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

 demonstrates how different INTERCAL is from standard programming languages. In C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, it could read as follows:

  1. include


int main
{
printf("Hello, world!\n");
return 0;
}


The equivalent program in C-INTERCAL is longer and harder to read:


DO ,1 <- #13
PLEASE DO ,1 SUB #1 <- #238
DO ,1 SUB #2 <- #108
DO ,1 SUB #3 <- #112
DO ,1 SUB #4 <- #0
DO ,1 SUB #5 <- #64
DO ,1 SUB #6 <- #194
DO ,1 SUB #7 <- #48
PLEASE DO ,1 SUB #8 <- #22
DO ,1 SUB #9 <- #248
DO ,1 SUB #10 <- #168
DO ,1 SUB #11 <- #24
DO ,1 SUB #12 <- #16
DO ,1 SUB #13 <- #162
PLEASE READ OUT ,1
PLEASE GIVE UP

Hello world cannot be implemented in INTERCAL-72 since the language lacks a facility for text output. Only "butchered" Roman numerals can be printed.

Abandon all sanity

In the article "A Box, Darkly: Obfuscation, Weird Languages, and Code Aesthetics", INTERCAL is described under the heading "Abandon all sanity, ye who enter here: INTERCAL". The compiler and commenting strategy are among the "weird" features described:

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK