Talk:Three variable modification language

From Esolang
Jump to navigation Jump to search

Hello World program

My previous Hello, World! program turned out to be a Heii, Wloia program, so here's an actual Hello, World! program:

*aa*ac*cc-ca<aRa-ba*ba*ba-ca<aRc+bc+bb+bc-ac<c<cRa+ac<c/caRbRc+bc+bb+bc-ac<cRc+bc+ac<cRa*ac*aa-ca<aRa*ab-bc-ac<c+ca<aRa-ca<aRb+bb+bb+ab<bRbRc*bb*bb+bb-bc<c

Here's the interpreter I used to test it written in SWI-Prolog, please check if it's accurate:

parse_tvml([]) --> ``.

parse_tvml([pnt(X)|T]) --> `>`, variable(X), parse_tvml(T).
parse_tvml([out(X)|T]) --> `<`, variable(X), parse_tvml(T).
parse_tvml([neg(X)|T]) --> `!`, variable(X), parse_tvml(T).
parse_tvml([res(X)|T]) --> `R`, variable(X), parse_tvml(T).

parse_tvml([add(X, Y)|T]) --> `+`, variable(X), variable(Y), parse_tvml(T).
parse_tvml([sub(X, Y)|T]) --> `-`, variable(X), variable(Y), parse_tvml(T).
parse_tvml([mul(X, Y)|T]) --> `*`, variable(X), variable(Y), parse_tvml(T).
parse_tvml([dvd(X, Y)|T]) --> `/`, variable(X), variable(Y), parse_tvml(T).

parse_tvml([whl(X, L)|T]) --> `w[`, variable(X), parse_tvml(L), `]`, parse_tvml(T).
parse_tvml([iff(X, L)|T]) --> `i[`, variable(X), parse_tvml(L), `]`, parse_tvml(T).

variable(a) --> `a`.
variable(b) --> `b`.
variable(c) --> `c`.

run_tvml(P) :- run_tvml_vars(P, vrs(3, -2, -1), _).

run_tvml_vars([], Vars, Vars).

run_tvml_vars([pnt(X)|T], Vars, Final) :- getVar(X, XV, Vars), write(XV), run_tvml_vars(T, Vars, Final).
run_tvml_vars([out(X)|T], Vars, Final) :- getVar(X, XV, Vars), char_code(Out, XV), write(Out), run_tvml_vars(T, Vars, Final).
run_tvml_vars([neg(X)|T], Vars, Final) :- getVar(X, XV, Vars), NewXV is -XV, setVar(X, NewXV, Vars, NewVars), run_tvml_vars(T, NewVars, Final).
run_tvml_vars([res(X)|T], Vars, Final) :- getVar(X, XV, vrs(3, -2, -1)), setVar(X, XV, Vars, NewVars), run_tvml_vars(T, NewVars, Final).

run_tvml_vars([add(X, Y)|T], Vars, Final) :- getVar(X, XV, Vars), getVar(Y, YV, Vars), NewYV is XV+YV, setVar(Y, NewYV, Vars, NewVars), run_tvml_vars(T, NewVars, Final).
run_tvml_vars([sub(X, Y)|T], Vars, Final) :- getVar(X, XV, Vars), getVar(Y, YV, Vars), NewYV is XV-YV, setVar(Y, NewYV, Vars, NewVars), run_tvml_vars(T, NewVars, Final).
run_tvml_vars([mul(X, Y)|T], Vars, Final) :- getVar(X, XV, Vars), getVar(Y, YV, Vars), NewYV is XV*YV, setVar(Y, NewYV, Vars, NewVars), run_tvml_vars(T, NewVars, Final).
run_tvml_vars([dvd(X, Y)|T], Vars, Final) :- getVar(X, XV, Vars), getVar(Y, YV, Vars), NewYV is XV//YV, setVar(Y, NewYV, Vars, NewVars), run_tvml_vars(T, NewVars, Final).

run_tvml_vars([whl(X, L)|T], Vars, Final) :- getVar(X, XV, Vars), XV =< 0, !, run_tvml_vars(T, Vars, Final) ;
                                             getVar(X, XV, Vars), XV > 0, run_tvml_vars(L, Vars, NewVars), !, run_tvml_vars([whl(X, L)|T], NewVars, Final).
run_tvml_vars([iff(X, L)|T], Vars, Final) :- getVar(X, XV, Vars), XV > 0, !, run_tvml_vars(T, Vars, Final) ;
                                             getVar(X, XV, Vars), XV =< 0, run_tvml_vars(L, Vars, NewVars), !, run_tvml_vars(T, NewVars, Final).

getVar(a, A, vrs(A, _, _)).
getVar(b, B, vrs(_, B, _)).
getVar(c, C, vrs(_, _, C)).

setVar(a, A, vrs(_, B, C), vrs(A, B, C)).
setVar(b, B, vrs(A, _, C), vrs(A, B, C)).
setVar(c, C, vrs(A, B, _), vrs(A, B, C)).

:- use_module(library(readutil)).

main :- read_file_to_codes("tvml.txt", Program, []), parse_tvml(Parsed, Program, []), run_tvml(Parsed).

?- main.

PkmnQ (talk) 06:36, 20 September 2022 (UTC)

Adding 1

You can set up variables like this:

+ba-bb

Which makes them:

a = 1
b = 0
c = -1

Which is perfectly compatible with incrementing and decrementing.

Or even better:

+ba-bb-cc

Which allows 2 free variables:

a = 1
b = 0
c = 0

To decrement, just negate a, add with a and then negate a again:

!a+av!a

Where v is one of the free variables.

RE: Well I guess that allows hello world to be like 100 times easier, its just tedious thats all. But yea actually this is kind of a really insane thing to find.