esolang

Preserve Line Numbers

Number every line, and the interpreter keeps the numbers and throws the lines away.

None1, 2023 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 1

The idea

None1 made Preserve Line Numbers in 2023 as the twin of Remove Line Numbers. Both read a text in which every line starts with its own line number. Remove Line Numbers prints the text without the numbers. This one prints the numbers without the text.

Read the story

So it can print only one thing, the numbers from 1 up, one per line. In return the lines 1 to n, each ended by a line feed, print themselves, so it has infinitely many quines.

The machine

The reference interpreter is about 30 lines of C++. It reads a number with scanf, checks it against a counter, reads the rest of the line and prints the counter. The first number that is missing or wrong prints Invalid syntax and stops.

Since scanf skips all whitespace before a number, empty lines between numbered lines do no harm. A line without a number does.

Example

The program of the numbers 1 to 10 on ten lines prints exactly those ten lines.
Expected: 1 2
Expected: 1 Invalid syntax

The program of the numbers 1 to 10 on ten lines prints exactly those ten lines.

Patterns it teaches

  • Quine: the lines 1 to n, each ended by a line feed, print themselves.

Further

Also in Jokes

Write your own in Run Convert a program from Preserve Line Numbers

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: preserve-line-numbers.

Command line

shib run preserve-line-numbers -e '1 '
shib manual preserve-line-numbers

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/preserve-line-numbers.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org