esolang

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

Expected: 42

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.

LineDoes
PLEASE SET VAR X -> 6 INTEGERSet a variable; also STRING, FLOAT and ARRAY
PLEASE --> XPrint a variable and a space, a string inside double quotes
PLEASE PRINT some wordsPrint the words and a space
PLEASE NEWLINEEnd the line
PLEASE ADD X 2 3 YAdd numbers and variables and keep the sum in Y; also MUL
PLEASE SUB 10 3 YStart from 10, then take away every number, 10 included
PLEASE MOD X 4 YThe remainder
PLEASE ADDTO L XAppend to an array; INSERT, DELETE and GETOUT count from 1
PLEASE GETINPUT XRead a line
PLEASE COME FROM 2 TO 4Run lines 2 to 4 once more
PLEASE ABSTAIN FROM PRINTSkip 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.
Expected: "Hello"
Expected: 42
Expected: -3

The comment from the specification, and a line run twice by COME FROM.

Expected: INVALID SYNTAX: ['PLEASE', 'IGNORE', 'this', 'text', 'is', 'not', 'executed']
Expected: once "once"

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

Further

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-intercal

Source

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