I want to use Tau Prolog together with JavaScript on a Node Server, following this tutorial, which works well. I need to convert the answers in a JavaScript compatible format, especially lists to arrays, or objects and vice versa.
I changed the Prolog program and goal in a way that it returns a list
Program: test(t, [64,65,100,120]).
Goal: test(t, X).
which returns with
console.log(session.format_answer(answer));
X = [64,65,100,120]
too the console. How can I get only the list and assign it to a js variable?
I tried
answer.lookup("X")
which gives me
Term {
ref: 1258,
id: '.',
args: [
Num { is_float: false, value: 64 },
Term { ref: 1257, id: '.', args: [Array], indicator: './2' }
],
indicator: './2'
}
Which is not very comfortable to access.
The args
array seems to be the list. I managed to get single list elements with
console.log(answer.links.X.args[1].args[1].args);
to get the third list element.
What is the best way to use complex answers and lists in JavaScript?