Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

  1. Home

WAP to reverse a list

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”]
Previous
Next Post »