init :- retractall(value(_)), assert(value(0)).

run :- init, prompt(_, '> '),
       repeat, read(X), do(X), X == exit, !.

do(set(V)) :- retract(value(_)), assert(value(V)).

do(print) :- value(V), writeln(V).

do(exit).

do(add(X)) :- value(V0), V is V0 + X, do(set(V)).

%do(sub(X0)) :- X is -X0, do(add(X)).

do(sub(X0)) :- do(add(-X0)). % works!

run0 :- prompt(_, '> '), repeat, read(T), format('Read ~w~n', T), T = exit, !.

