Hakerh
Hakerh is an esolang by User:TBPO that imitates User:Hakerh400's esolangs. I made a timestamp below to mark where my transformation into Hakerh400 begun:
Syntax
The program consists of function definitions:
f(X) = Y
Where uppercase letters (except T, F and N) are any expressions.
T, F and N are built-in functions that return themselves.
f returns a function with name f.
X(Y)
calls function X with argument Y.
X[Y]
returns Y if X[Y]
is T and N if isn't.
Syntactic sugar
There is some syntactic sugar to simplify and shorten the code. For example, let a, b
is equivalement to:
a(x) = a b(x) = b
f(X,Y)
is equivalement to f(X)(Y)
, and f(X,Y) = Z
is equivalement to:
f(X) = g g(Y) = Z
f(X.Y) = Z
:
f(X) = Z f(Y) = Z
,
has higher priority over .
, so f(X.Y,Z) = W
is:
f(X) = g f(Y) = g g(Z) = W
If a function isn't defined and isn't an argument of any function on the execution stack, it returns a unique function that returns itself.
Execution
Program execution:
- Take input.
- Check is it a valid Hakerh expression. If not, replace it with
_(_)
. - Evaluate input as Hakerh expression.
- Output the result.
A function call f(X)
is evaluated by the following:
- Iterate through the function definitions, starting from the first.
- Current definition will be written as
g(Y) = Z
.
- If
g
isn'tf
as the function, skip. - If X evaluates to N and Y is N, return N.
- If X or Y evaluates to N, skip.
- Replace all instances of
Y
inZ
withX
and return
- Current definition will be written as
- If no definition is found, evaluate X and return unique function which returns itself.
Recursion is allowed.
Intention
There are two reasons why I created this language:
- To begin the transformation into User:Hakerh400,
- To explore the simulation of sets and types by functions. Set can be simulated by a function that returns T if value is in the set and F otherwise. Set defined in such way can also simulate type, because
f[x]
in function definition causes the definition to be used only if x is in f.
Examples
SKI Calculus
This proves it meta Turing-complete.
I(x) = x K(x,y) = x S(x,y,z) = x(z,y(z))
Basic relations
eq(x,x) = T eq(x,y) = F !(F) = T !(x) = F or(F,F) = F or(x,y) = T and(T,T) = T and(x,y) = F nor(x,y) = !(or(x,y)) nand(x,y) = !(and(x,y)) neq(x,y) = !(eq(x,y)) apply(x,y) = x(y)
Natural numbers
let 0 N(0) = T N(S(N[x])) = T P(S(N[x])) = x N(P(0)) = F eq(S(a),S(b)) = eq(a,b) alt(0) = F alt(S(alt[x]) = F alt(x) = T nat(alt[x]) = F