PHL 1.0

From Esolang
Jump to: navigation, search
PHL 1.0
Paradigm(s) procedural, imperative
Designed by User:GermanyBoy
Appeared in 2012 (designed), 2014 (published)
Memory system variable-based
Dimensions one-dimensional
Computational class Unknown
Reference implementation [1]
File extension(s) .phl


Proceed High Language 1.0 (also known as PROCEED) is a mildly esoteric programming language created by User:GermanyBoy in 2012.

Syntax

There are three syntactical elements: procedure declaration, procedure or function call and a string constant. Everything that is not a declaration or a call is a constant. PHL 1.0 is based on substitution: a declaration is replaced with the name of the procedure and a call is replaced with the return value.

A basic declaration looks like this:

procedure[ call1; call2; call3; ... calln ]

A procedure can contain an infinite number of calls. No spaces are allowed between The name of the procedure and [. An anonymous function is like a basic declaration but without name.

A call is very similar to a declaration, except that [ and ] are replaced by ( and ).

procedure( arg1, arg2, arg3, ... argn )

Again, no spaces should occur between the name and the (.

Example:

printsum[
    println(The sum of A and B:);
    println(add(get(A), get(B)))
]

Built-in functions

Function Description
if(;s;f;f) Calls the first procedure if the condition evaluates to true, otherwise the second. Condition is in format (val1)(op)(val2) where (val1) and (val2) are values and (op) is either ==, !=, <, >, <= or >=.

Example:
if(get(A)==get(B), [println(A is B!)], [println(A is not B)])
get(;s) = ;o Gets a variable.
set(;s;o) Sets a variable.
add(;i;i) = ;i Addition
sub(;i;i) = ;i Subtraction
mul(;i;i) = ;i Multiplication
div(;i;i) = ;i Division
mod(;i;i) = ;i Modulo
strCat(;s;s) = ;s Concatenation
print(;s) Prints a string.
println(;s) Prints a line.
read() = ;s Reads a character.
readln() = ;s Reads a line.

Commands included in the Javascript interpreter:

Function Description
alert(;s) Creates a popup dialog.
prompt(;s) = ;s Creates an input dialog.

Examples

Hello World

main[
    println(Hello World!)
]

Fibonacci sequence

main[
    set(A, 0);
    set(B, 1);
    set(C, 0);
    set(I, 0);
    loop[
        if(get(I)<10, [
            set(C, add(get(A), get(B)));
            set(A, get(B));
            set(B, get(C));
            set(I, add(get(I), 1));
            println(get(I): get(C));
            loop();
        ], []);
    ]();
]

Truth-machine

Uses prompt() as the input function ~ change to read() if using command line input.

main[
    if(prompt()==0, [
        println(0)
    ], [
        loop[
            println(1);
            loop();
        ]()
    ])
]

Stack

As the main data structure of PHL 1.0 is a hash map, can it be used to simulate a stack (or a queue or everything else).

initStack[
    set(stack, 0)
]
push[
    set(stack, add(get(stack), 1));
    set(strCat(stack_, get(stack)), get(value))
]
pop[
    set(value, get(strCat(stack_, get(stack))));
    set(stack, sub(get(stack), 1));
]

Example usage:

main[
    initStack();
    set(value, 1); push();
    set(value, 2); push();
    set(value, 3); push();
    pop(); println(get(value));
    pop(); println(get(value));
    pop(); println(get(value));
]

Computational class

PHL 1.0 is believed to be Turing complete, but this has not been proved yet.

External resources