You are on page 1of 1

%Program to insert an element to the head of the list.

%Facts.
notmem(X,[]).
%Rules.
notmem(X,[H|T]):- X\=H,notmem(X,T).
insert(X,L,[X|L]):- write("New list is "),write([X|L]),nl.
add_to_head(X,[H|T]):- notmem(X,[H|T]),insert(X,[H|T],L).
%Queries.
?- read(X),read(L),write("List is "),write(L),nl,add_to_head(X,L).

You might also like