r/prolog • u/playingwithunicorns • Jan 22 '19
[Beginner] append in a recursion.
I want a program that puts the last N items in a list,
So far I have;
returnN(S,[Head|Tail]):-
reverse([Head|Tail],[Head2|Tail2]),
delete_last([Head|Tail],X),
%append in new List Goes here
M is S-1,
returnN(M,X).
Head2 contains the element I want to concatenate with a list throughout each iteration of the recursion. I cant do append([Head2],[L],L). because L is empty in the first iteration. I would appreciate any help, thanks :)
0
Upvotes
4
u/[deleted] Jan 22 '19
I was about to help but then I realized I have no freakin idea what it is you are trying to achieve.