Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
INTERCAL
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Syntax == Input (using the <code>WRITE IN</code> instruction) and output (using the <code>READ OUT</code> 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]].<ref name="manual72"/> More recent versions have their own I/O systems.<ref name="clc"/><ref name="manualick"/> Comments can be achieved by using the inverted statement identifiers involving NOT or N'T; these cause lines to be initially ABSTAINed from so that they have no effect.<ref name="manual72"/> (A line can be ABSTAINed from even if it does not have valid syntax; syntax errors happen at runtime, and only then when the line is un-ABSTAINed.)<ref name="manual72"/> === Data structures === INTERCAL-72 (the original version of INTERCAL) had only four [[data type]]s: the 16-[[bit]] [[integer]] (represented with a <code>.</code>, called a "spot"), the 32-bit integer (<code>:</code>, a "twospot"), the [[Array data type|array]] of 16-bit integers (<code>,</code>, a "tail"), and the array of 32-bit integers (<code>;</code>, a "hybrid"). There are 65535 available variables of each type, numbered from <code>.1</code> to <code>.65535</code> for 16-bit integers, for instance. However, each of these variables has its own [[stack (data structure)|stack]] on which it can be pushed and popped (STASHed and RETRIEVEd, in INTERCAL terminology), increasing the possible complexity of data structures.<ref name="manual72"/> More modern versions of INTERCAL have by and large kept the same data structures, with appropriate modifications; TriINTERCAL, which modifies the [[radix]] with which numbers are represented, can use a 10-[[trit (computing)|trit]] type rather than a 16-bit type,<ref name="manualick"/> 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.<ref name="clc"/> Arrays are dimensioned by assigning to them as if they were a [[scalar (computing)|scalar]] variable. Constants can also be used, and are represented by a <code>#</code> ("mesh") followed by the constant itself, written as a [[decimal]] number; only integer constants from 0 to 65535 are supported.<ref name="manual72"/> === 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. {| class="wikitable" |+ INTERCAL operators<ref name="clc"/><ref name="manual72"/><ref name="manualick"/> |- ! Operator ! INTERCAL-72 characters ! C-INTERCAL characters ! CLC-INTERCAL characters |- | INTERLEAVE / MINGLE | <code>c</code> [[backspace]] <code>/</code> | <code>Β’</code>, <code>$</code>, <code>c</code> backspace <code>/</code> | <code>Β’</code> |- | SELECT || <code>~</code> || <code>~</code> || <code>~</code> |- | AND || <code>&</code> || <code>&</code> || <code>&</code> |- | OR || <code>V</code> || <code>V</code> || <code>V</code> |- | XOR | <code>V</code> backspace <code>-</code> | <code>V</code> backspace <code>-</code>, <code>?</code>, <code>β</code> | <code>V</code> backspace <code>-</code>, <code>Β₯</code> |} Contrary to most other languages, AND, OR, and XOR are [[Unary operation|unary]] operators, which work on consecutive bits of their argument; the [[most significant bit]] of the result is the operator applied to the least significant and most 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 (programming language)|C]].) 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 (1'''1'''0'''0'''1'''1''' 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 <code>'</code> ("spark"), which matches another spark, and <code>"</code> ("rabbit ears"), which matches another rabbit ears; the programmer is responsible for using these in such a way that they make the expression unambiguous).<ref name="manual72"/> === Control structures === INTERCAL statements all start with a "statement identifier"; in INTERCAL-72, this can be <code>DO</code>, <code>PLEASE</code>, or <code>PLEASE DO</code>, 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]] in INTERCAL-72 that was mentioned in the C-INTERCAL manual),<ref name="manualick"/> or an inverted form (with <code>NOT</code> or <code>N'T</code> appended to the identifier).<ref name="manual72"/> Backtracking INTERCAL, a modern variant, also allows variants using <code>MAYBE</code> (possibly combined with PLEASE or DO) as a statement identifier, which introduces a choice-point.<ref name="backtrack">{{cite web|url=http://www.cse.unsw.edu.au/~malcolmr/intercal/backtracking.html |title=Backtracking in Intercal |publisher=Cse.unsw.edu.au |date=2006-04-11 |access-date=2012-03-10}}</ref> 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 <code>%50</code>, which defaults to 100%.<ref name="manual72"/> In INTERCAL-72, the main control structures are NEXT, RESUME, and FORGET. <code>DO (''line'') NEXT</code> 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); <code>DO FORGET ''expression''</code> 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 <code>DO RESUME ''expression''</code> removes ''expression'' entries from the call stack and jumps to the last line remembered.<ref name="manual72"/> C-INTERCAL also provides the [[COME FROM]] instruction, written <code>DO COME FROM (''line'')</code>; CLC-INTERCAL and the most recent C-INTERCAL versions also provide computed COME FROM (<code>DO COME FROM ''expression'')</code> and NEXT FROM, which is like COME FROM but also saves a return address on the NEXT STACK.<ref name="clc"/> 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.<ref name="manual72"/> === Hello, world === The traditional [[Hello world program|"Hello, world!" program]] demonstrates how different INTERCAL is from standard programming languages. In [[C (programming language)|C]], it could read as follows: <syntaxhighlight lang="c"> #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } </syntaxhighlight> The equivalent program in C-INTERCAL is longer and harder to read: <syntaxhighlight lang="basic"> 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 </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)