You are on page 1of 1

%Program to add an element at the head using append.

%Facts.
append1([],L,L).
%Rules.
append1([X|L1],L2,[X|L3]):- append1(L1,L2,L3).
add_to_head(X,L):- append1(X,L,R),write(" New list is "),write(R),nl.
%Query.
?- read(L1),read(L2),write(" Element to be added "),write(L1),nl,write(" List is
"),write(L2),nl,add_to_head(L1,L2).

You might also like