I am trying to append an integer N times to a list. So far, I know how to append two lists and I am trying to use that calling a recursive call so it appends N times an integer.
I have already tried:
append(,L,L). append([H|T],L2,[H|L3]) :- append(T,L2,L3). list(X,N,L,L2) :- N>0, append([X],L,L2), N is N-1, list(X,N,L2,L3). % Test of the code 1 ?- list(3,6,A,B). false. % Expected Result [3,3,3,3,3,3]
Assuming you can use standard built-in and library predicates:
?- I = 3, N = 7, findall(I, between(1,N,_), L). I = 3, N = 7, L = [3, 3, 3, 3, 3, 3, 3].