Utente:IAmJoined/Sandbox/INTERCAL

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

ñee

Don Woods, uno degli autori di INTERCAL, nel 2010
Jim Lyon, l'altro autore di INTERCAL, nel 2005

INTERCAL (Compiler Language With No Pronounceable Acronym), è un linguaggio di programmazione esoterico creato come parodia da Don Woods e James M. Lyon, due studenti dell'Università di Princeton, nel 1972. Il linguaggio fa satira sugli aspetti dei vari linguaggi di programmazione del tempo,[1] e sulla proliferazione dei costrutti e delle notazioni proposte negli anni '60.

Ci sono due versioni correntemente mantenute di INTERCAL: C-INTERCAL, mantenuto da Eric Steven Raymond,[2] e CLC-INTERCAL, mantenuto da Claudio Calvelli.[3]

Storia[modifica | modifica wikitesto]

Secondo il manuale originale degli autori,[4]

(EN)

«The full name of the compiler is "Compiler Language With No Pronounceable Acronym," which is, for obvious reasons, abbreviated "INTERCAL."»

(IT)

«Il nome completo del compilatore è "Compiler Language With No Pronounceable Acronym," che, per ovvie ragioni, è abbreviato a "INTERCAL."»

L'implementazione originale di Princeton usava le schede perforate e il set di caratteri EBCDIC. Per permettere a INTERCAL di funzionare sui computer che usano ASCII, si è resa necessaria la sostituzione di due caratteri: $ ha sostituito ¢ come l'operatore mingle, "che rappresenta il crescente costo del software in relazione all'hardware", e ? ha sostituito come operatore unario di disgiunzione esclusiva per "esprimere correttamente la reazione della persona media al primo incontro con la disgiunzione esclusiva".[4] Nelle versioni più recenti di C-INTERCAL, i vecchi operatori sono supportati come alternativa; i programmi INTERCAL possono essere ora codificati in ASCII, Latin-1, o UTF-8.[5]

Dettagli[modifica | modifica wikitesto]

INTERCAL è stato pensato per essere un linguaggio di programmazione completamente diverso da tutti gli altri. Operazioni comuni negli altri linguaggi hanno una sintassi criptica e ridondante in INTERCAL. Dal manuale di riferimento di INTERCAL:[4]

(EN)

«It is a well-known and oft-demonstrated fact that a person whose work is incomprehensible is held in high esteem. For example, if one were to state that the simplest way to store a value of 65536 in a 32-bit INTERCAL variable is:

DO :1 <- #0¢#256

any sensible programmer would say that that was absurd. Since this is indeed the simplest method, the programmer would be made to look foolish in front of his boss, who would of course happen to turn up, as bosses are wont to do. The effect would be no less devastating for the programmer having been correct.»

(IT)

«Com'è ben noto e dimostrato, le persone il cui lavoro è incomprensibile sono rispettate e ammirate. Per esempio, se qualcuno dicesse che il modo più semplice per memorizzare il valore 65536 in una variabile di INTERCAL a 32-bit è:

DO :1 <- #0¢#256

qualsiasi programmatore ragionevole direbbe che ciò è assurdo. Poiché questo è realmente il metodo più semplice, il programmatore finirebbe con l'apparire ridicolo di fronte al proprio capo, che sicuramente comparirebbe per caso, com'è solito accadere. L'effetto non è reso meno devastante dal fatto che il programmatore abbia ragione.»

INTERCAL dispone di moltre altre funzionalità progettate per renderlo ancora più esteticamente sgradevole al programmatore: usa statement come "READ OUT", "IGNORE", "FORGET", e modificatori come "PLEASE". Quest'ultima parola chiave fornisce due ragioni perché il compilatore possa rifiutare il programma: se "PLEASE" non compare abbastanza volte, il programma è considerato non abbastanza educato, e il messaggio d'errore lo riporta; se compare troppo spesso, il programma potrebbe essere rifiutato per l'eccessiva gentilezza. Anche se questa funzionalità esisteva nel compilatore INTERCAL originale, non era documentata.[6]

Nonostante la sintassi intenzionalmente ottusa e prolissa del linguaggio, INTERCAL è ciò nondimeno Turing-completo: con sufficiente memoria, INTERCAL può risolvere qualsiasi problema che una macchina di Turing universale può risolvere. La maggior parte delle implementazioni di INTERCAL lo fanno tuttavia molto lentamente. Un benchmark basato sul Crivello di Eratostene per il calcolo di tutti i numeri primi minori di 65536, è stato fatto usando un Sun SPARCstation 1. In C, ci è voluto meno di mezzo secondo; lo stesso programma in INTERCAL ha finito dopo oltre 17 ore.[7]

Documentazione[modifica | modifica wikitesto]

Il "tortuoso diagramma" dal manuale di riferimento di INTERCAL, presumibilmente per spiegare il funzionamento dell'operatore "select"

Il manuale di riferimento di INTERCAL contiene molte istruzioni paradossali, prive di senso o altrimenti umoristiche:

(EN)

«Caution! Under no circumstances confuse the mesh with the interleave operator, except under confusing circumstances!»

(IT)

«Attenzione! In nessuna circostanza confondere l'operatore "mesh" con l'operatore "interleave", eccetto in caso di confusione delle circostanze!»

Il manuale contiene anche una "tonsilla", com'è spiegato in questa nota a piè di pagina[4]:

(EN)

«4) Since all other reference manuals have Appendices, it was decided that the INTERCAL manual should contain some other type of removable organ.»

(IT)

«4) Siccome tutti gli altri manuali di riferimento hanno un appendice, è stato deciso che il manuale di INTERCAL debba avere qualche altro tipo di organo rimovibile.»

Il manuale INTERCAL dà nomi inusuali a tutti i caratteri ASCII non-alfanumerici: gli apici singoli e doppi sono "sparks" (scintille) e "rabbit ears" (orecchie di coniglio) rispettivamente. (Costituisce eccezione l'E commerciale: come dice il Jargon File, "cosa potrebbe essere più stupido?") L'operatore di assegnamento, rappresentato dal simbolo di uguaglianza (il "mezzo cancelletto" in INTERCAL) in moltri altri linguaggi di programmazione, in INTERCAL è una freccia a sinistra, <-, a cui ci si riferisce come "gets" (prende) ed è fatta da un "angle" (angolo) e un "worm" (verme).

Syntax[modifica | modifica wikitesto]

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.[4] More recent versions have their own I/O systems.[3][6]

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.[4] (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.)[4]

Data structures[modifica | modifica wikitesto]

INTERCAL-72 (the original version of INTERCAL) had only four data types: the 16-bit integer (represented with a ., called a "spot"), the 32-bit integer (:, a "twospot"), the 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 on which it can be pushed and popped (STASHed and RETRIEVEd, in INTERCAL terminology), increasing the possible complexity of data structures.[4] (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 type rather than a 16-bit type),[6] 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.[3] Arrays are dimensioned by assigning to them as if they were a scalar variable. Constants can also be used, and are represented by a # ("mesh") followed by the constant itself, written as a decimal number; only integer constants from 0 to 65535 are supported.[4]

Operators[modifica | modifica wikitesto]

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.

INTERCAL operators[3][4][6]
Operator INTERCAL-72 characters C-INTERCAL characters CLC-INTERCAL characters
INTERLEAVE / MINGLE c backspace / ¢, $, c backspace / ¢
SELECT ~ ~ ~
AND & & &
OR V V V
XOR V backspace - V backspace -, ?, V backspace -, ¥

Contrary to most other languages, AND, OR, and XOR are unary operators, which work on consecutive bits of their argument; the most significant bit 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.) 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).[4]

Control structures[modifica | modifica wikitesto]

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 in INTERCAL-72 that was mentioned in the C-INTERCAL manual),[6] or an inverted form (with NOT or N'T appended to the identifier).[4] 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.[8] 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%.[4]

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.[4]

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.[3]

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.[4]

Hello, world[modifica | modifica wikitesto]

The traditional "Hello, world!" program demonstrates how different INTERCAL is from standard programming languages. In C, it could read as follows:

#include <stdio.h>

int main(void) {
    printf("Hello, world!\n");
    return 0; // _exit(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

Dialects[modifica | modifica wikitesto]

The original Woods–Lyon INTERCAL was very limited in its input/output capabilities: the only acceptable input were numbers with the digits spelled out, and the only output was an extended version of Roman numerals.

The C-INTERCAL reimplementation, being available on the Internet, has made the language more popular with devotees of esoteric programming languages.[9] The C-INTERCAL dialect has a few differences from original INTERCAL and introduced a few new features, such as a COME FROM statement and a means of doing text I/O based on the Turing Text Model.[6]

The authors of C-INTERCAL also created the TriINTERCAL variant, based on the Ternary numeral system and generalizing INTERCAL's set of operators.[6]

A more recent variant is Threaded Intercal, which extends the functionality of COME FROM to support multithreading.[10]

Impact and discussion[modifica | modifica wikitesto]

In the article "A Box, Darkly: Obfuscation, Weird Languages, and Code Aesthetics",[9] 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:

«The compiler, appropriately named "ick", continues the parody. Anything the compiler can't understand, which in a normal language would result in a compilation error, is just skipped. This "forgiving" feature makes finding bugs very difficult; it also introduces a unique system for adding program comments. The programmer merely inserts non-compileable text anywhere in the program, being careful not to accidentally embed a bit of valid code in the middle of their comment.»

In "Technomasochism",[11] Lev Bratishenko characterizes the INTERCAL compiler as a dominatrix:

«If PLEASE was not encountered often enough, the program would be rejected; that is, ignored without explanation by the compiler. Too often and it would still be rejected, this time for sniveling. Combined with other words that are rarely used in programming languages but appear as statements in INTERCAL, the code reads like someone pleading.»

See also[modifica | modifica wikitesto]

References[modifica | modifica wikitesto]

  1. ^ The A-Z of Programming Languages: INTERCAL, su techworld.com.au, Techworld, 4 luglio 2008. URL consultato il 10 marzo 2012.
  2. ^ The INTERCAL Resources Page, su catb.org. URL consultato il 10 marzo 2012.
  3. ^ a b c d e Clc-Intercal, su clc.intercal.org.uk, Clc-Intercal, 1º aprile 2010. URL consultato il 10 marzo 2012.
  4. ^ a b c d e f g h i j k l m n o INTERCAL reference manual (ps), su oops.se. URL consultato il 10 marzo 2012 (archiviato dall'url originale il 16 luglio 2011).
  5. ^ Princeton and Atari Syntax – C-INTERCAL 0.27 Revamped Instruction Manual, su c.intercal.org.uk. URL consultato il 12 novembre 2012.
  6. ^ a b c d e f g C-INTERCAL supplemental reference manual, su progsoc.uts.edu.au (archiviato dall'url originale il 23 febbraio 2008).
  7. ^ Charles Stross, Intercal -- the Language From Hell, in Computer Shopper (UK), September 1992.
  8. ^ Backtracking in Intercal, su cse.unsw.edu.au, 11 aprile 2006. URL consultato il 10 marzo 2012.
  9. ^ a b Michael Mateas, A Box, Darkly: Obfuscation, Weird Languages, and Code Aesthetics (PDF), pp. 144–153.
  10. ^ Threaded Intercal, su cse.unsw.edu.au, 9 giugno 2004. URL consultato il 10 marzo 2012.
  11. ^ Lev Bratishenko, Technomasochism, in Cabinet, n. 36, Winter 2009. URL consultato il 27 maggio 2014.

External links[modifica | modifica wikitesto]