Can someone help me find the error in these rules?
concat([], List, List).
concat([Head|[]], List, [Head|List]).
concat([Head|Tail], List, Concat) :- concat(Tail, List, C), concat(Head, C, Concat).
Trying to concatenate two lists fails:
| ?- concat([1,2], [4,7,0], What).
no
To fix your code, the way you intended it, you just need to transform
Headinto[Head]in your last call toconcat/3in your last clause. The problem was that you called your predicate withHeadonly as first argument, which is not a list.Though, here are several notes :
[Head|[]]is equivalent to[Head]Here is SWI-pl’s version, to hint you towards good prolog recursion :
You can find other resources on recent posts here or in Learn Prolog Now! tutorial if you want to learn how to use recursion properly.