I'm a complete beginner with Prolog and I wanted to know how to use ground/1
.
At the moment I have this code:
intertwine([], [], []).
intertwine([E|Es], Fs, [E|Gs]) :- intertwine(Es, Fs, Gs).
intertwine(Es, [F|Fs], [F|Gs]) :- intertwine(Es, Fs, Gs).
But when I try to call this in the shell:
intertwine([1,2],X,[1,a,2,b]).
I get the right answer X=[a,b]
, but the query doesn't end, as if it thinks there is another answer left. So, I press ";" and I get "false" as output. I read in another question's answer that I should use ground/1
to check whether the third list is already completely instantiated to handle the case.
Thing is, being a complete beginner, I have no clue how to do that. So is there someone kind enough to explain to me how ground works and how I can use it to check instantiation of a specific parameter and use that to not have the code check for an answer that isn't there?