English

From Esolang
Jump to navigation Jump to search
Not to be confused with ENGLISH, a (non-esoteric) SQL-like programming language used in the old Pick operating system, or ~English, an esoteric attempt at using a natural language as a programming language. Also not to be confused with !English, another programming language based on English syntax, or English+, yet another similar language, or enGLish, a similar language with graphical output.

English is a declarative programming language. Many people are familiar with it even if they don't know any other programming language.

Description

Programs are as declarative as they can be: a program is a natural language description of what the program does.

Examples

Hello World

This program writes "Hello World" (without quotes) to the output.
This program outputs Hello World.

99 Bottles of Beer

This program outputs 99 verses in the manner:
"N bottles of beer on the wall
N bottles of beer
Take one down and pass it around
N-1 bottles of beer on the wall",
where N is replaced by numbers from 99 to 1
and 1-1=0 is replaced by "No more".
After that there is the hundredth verse:
"No more bottles of beer on the wall
No more bottles of beer
Go to the store and buy some more
99 bottles of beer on the wall".

This one uses more replace:

This program outputs 99 verses in this manner:
"N bottles of beer on the wall,
N bottles of beer.
Take one down, pass it around,
N-1 bottles of beer on the wall",
where N is replaced by numbers from 99 to 0
and 1-1=0 is replaced by "No more".
If this is the 100th verse,
replace the second-to-last line by:
"Go to the store and buy some more"
and replace 0-1 by 99.

Cat program

This program outputs all input it recieves.

Quine

This program outputs its own source

or (as the former may be considered a cheat):

This program outputs some string followed by its quotation, and that string is
"This program outputs some string followed by its quotation, and that string is"

Self interpreter

This program reads a description of a program and executes it.

Bootstrap

Note: the "French" can be replaced by any natural language.

This program reads a description of a program and transpiles it to French.

Result (when the program is fed into itself):

Ce programme lit une description d'un programme et la traduit en francais.

Random boolean generator

This program tosses a coin and outputs "Yes" if it's tails or "No" if it's heads.

Truth Machine

This program reads input from user, output 0 if the input is 0, and output 1 infinitely if the input is 1.

(Author's note: English isn't my native language)

Turing completeness

It's obvious that English is Turing complete. For example, here is a Brainfuck interpreter:

Read "Brainfuck" article on Esolang wiki.
This is a Brainfuck interpreter.

It's shown here how one can include some specific knowledge into a program.

Computability

Of course English is uncomputable. It solves the halting problem:

Read "Halting Problem" article in Wikipedia.
This program solves the halting problem.

Errors

INCORRECT LANGUAGE

The code given is not in English.

INVALID SYNTAX

All words are valid, but the grammar isn't.

DIVISION BY ZERO

Self-explanatory.

Compilers

A compiler of English (usually to some other high-level language) is usually a programmer. They are usually humans and they can be quite buggy at times. However, the programmers are not able to compile English into another high-level language if the original source is uncomputable. Programmer compilers take more time than other compilers like 'gcc' or so, but they also have abilities to disassemble or decompile high-level language into English.

As can be seen in the Hello World example, there are multiple ways of expressing the same idea. And due to the ambiguous nature of human languages, the same is also true for a programs interpretation. Therefore, English can have different valid interpretations of the same program.

Some computer programs are also able to compile the English language. They are called natural language programming systems.

Machine Learning

Recent advances in machine learning made it possible for OpenAI to develop several models named Codex which use GPT-3 in order to understand a text prompt and generate code that applies to the prompt[1]. So, one could argue that Codex is a cross-compiler for English. And while it's impossible to achieve an accuracy of 100%, OpenAI's approach is most probably the closest one can get to compiling or interpreting English.

Example

Examples are created using OpenAI's JavaScript beta sandbox. The English source code is written as a comment above the code.

Hello World
/* This program outputs Hello World. */
var helloWorld = document.createElement('div');
helloWorld.innerHTML = 'Hello World';
document.body.appendChild(helloWorld);
99 Bottles of Beer
/* This program outputs 99 verses in this manner: "N bottles of beer on the wall, N bottles of beer. Take one down, pass it around, N-1 bottles of beer on the wall", where N is replaced by numbers from 99 to 0 and 1-1=0 is replaced by "No more". If this is the 100th verse, replace the second-to-last line by: "Go to the store and buy some more" and replace 0-1 by 99. */
var bottles = 99;
while (bottles >= 0) {
  var verse = document.createElement('div');
  verse.innerHTML = bottles + ' bottles of beer on the wall, ' + bottles + ' bottles of beer. Take one down, pass it around, ' + (bottles - 1) + ' bottles of beer on the wall';
  if (bottles == 0) {
    verse.innerHTML = 'No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall';
  }
  document.body.appendChild(verse);
  bottles--;
}

Localization

English is possibly the easiest esoteric programming language to localize to different human languages, although only Español is known to exist at the moment. They might help to introduce esoteric programming languages to a larger audience.

In Popular Culture

On the science fiction television series Star Trek, the crew of the USS Enterprise program the ship's main computer in this language.

External resources

  • english-lang is a parody repository for the English programming language.