I'm new in turbo prolog.I'm facing a problem in appending nested list. I want the goal like this-
Goal: mega_append([[1,3],[2,4,6],[0]],X)
Output should be X=[1,3,2,4,6,0]
I used the following codes:
domains
list=integer*
predicates
mega_append(list,list)
append(list,list,list)
clauses
mega_append([],[]).
mega_append([H|T],L3):-
mega_append(H,L1),
mega_append(T,L2),
append(L1,L2,L3).
mega_append(X,[X]).
append([],ListB,ListB).
append([X|List1],List2,[X|List3]):-
append(List1,List2,List3).
The program generates an error.It is "illegal variable type in this position." Then it indicates the position of H in the line- mega_append(H,L1). How can I get rid of this problem? Is there any mistake in my program? Please help me.
You're manipulating lists of lists, not lists of integers. Try
Then, fix your recursion. The version you wrote won't work in a statically typed variant of Prolog, which Turbo Prolog apparently is:
mega_append
is called recursively on the head of its first argument, which is of a different type then the argument itself (if it is of typeT*
, then its head must be of typeT
).And btw., the common name for this predicate is
concat/2
.