W-INTERCAL
INTERCAL for beginners. PLEASE means do it, DO means maybe.
Kiwitrader, 2016 · Turing complete: no · ●○○ easy · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Kiwitrader made W-INTERCAL in 2016 as a version of INTERCAL that novice programmers should learn instead. A line that starts with PLEASE always runs. A line that starts with DO runs with a chance of one in two. COME FROM takes line numbers and runs that stretch of the program once more, and ABSTAIN FROM switches a command off for the rest of the run.
Read the story
The specification comes with a Python interpreter of 392 lines, and this implementation runs programs the way it does, quirks included. The comment PLEASE IGNORE this text is not executed is a good example. The interpreter knows IGNORE only after DO, and there it checks the wrong word, so the comment prints itself as invalid syntax.
The machine
A program is lines of words split on spaces. The lines run once each, top to bottom, and COME FROM can run a stretch of them again. Nothing loops, so every program ends.
| Line | Does |
|---|---|
PLEASE SET VAR X -> 6 INTEGER | Set a variable; also STRING, FLOAT and ARRAY |
PLEASE --> X | Print a variable and a space, a string inside double quotes |
PLEASE PRINT some words | Print the words and a space |
PLEASE NEWLINE | End the line |
PLEASE ADD X 2 3 Y | Add numbers and variables and keep the sum in Y; also MUL |
PLEASE SUB 10 3 Y | Start from 10, then take away every number, 10 included |
PLEASE MOD X 4 Y | The remainder |
PLEASE ADDTO L X | Append to an array; INSERT, DELETE and GETOUT count from 1 |
PLEASE GETINPUT X | Read a line |
PLEASE COME FROM 2 TO 4 | Run lines 2 to 4 once more |
PLEASE ABSTAIN FROM PRINT | Skip every later PRINT |
A string can hold no space, since the line is split first. The "Hello world" falls apart into two words and sets nothing. DIV has no number of its own to start from. It divides whatever the previous calculation left behind, so PLEASE DIV 1 2 Y right after a sum of 5 keeps 2 in Y. Lines that COME FROM runs print their PRINT words in quotes. MOD writes the values of its two variables into the line itself, and DIV the value of its first, so the next run of that line still sees the old values.
Example
The comment from the specification, and a line run twice by COME FROM.
The comment from the specification, and a line run twice by COME FROM.
DO lines are left out, as they run only half the time. In this implementation the coin is a fixed sequence, so a program prints the same on every run. A DO COME FROM always fails, because by then the interpreter has put the list [1, 2] where the program used to be.
Patterns it teaches
- Hostile design: manners decide whether a line runs.
- Nondeterminism:
DOflips a coin.
Further
- esolangs.org/wiki/W-INTERCAL
- INTERCAL, the language it simplifies
See also
Also in Hostile
Write your own in Run Convert a program from W-INTERCAL
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: w-intercal.
Command line
shib run w-intercal -e 'ABSTAIN FROM ABSTAIN'shib manual w-intercalSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/w-intercal.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org