Here is a simple Prolog program to exhibit a problem that I currently have with my real code.
I am trying to write a Brainf*ck interpreter in Prolog, but it is not returning the right Output
I am running bf("+.", Output)
Expected Return - Output = [1]
Actual Return - Output = []
.
Output
looses its value when it returns to iterateProg(Prog,Output)
in bf2
.
Program is as follows:
bf2(Prog,Output):-
iterateProg(Prog,Output).
iterateProg([],_):- !.
iterateProg(Prog, Output):-
checkInstruction(Prog,Output, NewProg, NewOutput),
iterateProg(NewProg, NewOutput).
checkInstruction([Plus|ProgTail],Output,ProgTail,Output):-
char_code('+',Plus)
%increase memory by 1 for printing later.
.
checkInstruction([Period|ProgTail], Output, ProgTail, NewOutput):-
char_code('.',Period),
%take the value in memory from addition just now, we will assume it is 1
append(Output,[1],NewOutput).