WAP
to reverse a list.
domains
charlist=char*
symbolist=symbol*
integerlist=integer*
realist=real*
predicates
reverse(symbolist,symbolist)
reverse(charlist,charlist)
reverse(integerlist,integerlist)
reverse(realist,realist)
rev(integerlist,integerlist,integerlist)
rev(symbolist,symbolist,symbolist)
rev(realist,realist,realist)
rev(charlist,charlist,charlist)
clauses
reverse(L1,R):-rev(L1,[],R).
rev([],L,L).
rev([H|T],L,M):-rev(T,[H|L],M).
Output:-
Goal:
reverse([“1”,”2”,”3”],L)
L=[“3”,“2”,”1”]