The reverse operation arranges the items of a list in reverse order. For example, a list L = [a,b,c,d,e] when reversed will give output as [e,d,c,b,a]. To create a predicate, list_reverse(List, ReversedList), we must remember that,

  • If the input list is empty, then the reversed list will also be empty.
  • In the input list, elements are organized as [Head|Tail], but in the reversed list, elements in the Tail are recursively concatenated with the Head.

Add the instructions to implement list_rev predicate in kb5.pl and check the execution in console as shown in figure.

images
images

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *