I have a definition of conc
:
conc([], L2, L2).
conc([X1|R1], L2, [X1|RN]) :-
conc(R1, L2, RN).
I don't understand why conc([X | green], Y, [red, green, blue]).
returns false
rather than
X = [red],
Y = [blue]
What is the process of inference here?
Disclaimer: I don't know Prolog. The rest of this answer is an edumacated guess.
Your proposed solution of X = [red]
doesn't make sense because that would make X
a one-element list. Let's assume
X = red
instead.
That would give us
conc([red | green], [blue], [red, green, blue]).
With the second equation of conc
that turns into
conc(R1, L2, RN).
% with:
% X1 = red
% R1 = green
% L2 = [blue]
% [X1|RN] = [red, green, blue]
% i.e. X1 = red
% RN = [green, blue]
I.e.
conc(green, [blue], [green, blue]).
And now we're stuck because none of your conc
rules applies to green
.
The problem is [X | green]
because green
is not the tail of a list.
Did you mean [X, green]
instead?