esolang

PHL 1.0

Every call is replaced by its value and every declaration by its name, until only text is left.

Fergusq, 2012 · Turing complete: conjectured · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hello World!

The idea

Fergusq designed Proceed High Language 1.0 in 2012 and published it in 2014. It looks like an ordinary procedural language, but it works by substitution. A declaration name[ ... ] is replaced by the name of the procedure, and a call name( ... ) is replaced by the value it returns. Everything else is a string constant, so println(Hello World!) needs no quotes.

Read the story

That is how a loop is written. loop[ ... ]() declares loop, the declaration turns into the word loop, and the () after it makes a call. The procedure calls itself at its end to go round again. Variables live in one map, and the specification builds a stack on it with names like stack_3.

The machine

Built inDoes
if(x op y, f, g)Call f if the comparison holds, else g; op is == != < > <= or >=
get(name) set(name, value)Read or write a variable
add sub mul div modWhole number arithmetic on two arguments
strCat(a, b)Join two strings
print(s) println(s)Print, the second with a line feed
read() readln()Read a character or a line

Arguments are split at commas and trimmed of spaces. [ ... ] without a name declares a procedure without one, which is how if gets its two branches. A procedure takes no arguments and gives back nothing, so it talks to the rest of the program through variables, as the stack does. The original interpreter ran in a browser and also had prompt() and alert(). prompt() reads a line.

Example

The Fibonacci sequence.

The Fibonacci sequence. The value of each call is put into the text around it, so get(I): get(C) prints the count, a colon and the number.

Expected: 1: 1 2: 2 3: 3 4: 5 5: 8 6: 13 7: 21 8: 34 9: 55 10: 89

The stack and its example usage, as one program. Each push makes a variable named stack_ and the height, and each pop reads one back.

Expected: 3 2 1

The truth machine asks with prompt(), which reads a line.

Expected: 0

Further

Also in Rewriting

Write your own in Run Convert a program from PHL 1.0

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: phl-1-0.

Command line

shib run phl-1-0 -e 'main[
    println(Hello World!)
]'
shib manual phl-1-0

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/phl-1-0.js

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

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