While appending two lists, we add two lists or add one list as an element of the other list. If the element to be added is already present in the list, then the append function simply returns.

Before writing instructions to implement list_append(L1, L2, L3) predicate, note that,

If A is an element to be appended in list L1 that already has A, then the output will be L1 only.

Otherwise, a new list will be created as, L2 = [A|L1].

To implement list_append predicate in Prolog, add the following statements in kb5.pl and execute the instructions in console as given in figure.

images

Note that the (!) symbol, is known as cut. Here it is used because we want that if the first line is executed successfully, then we cut it, so that the next operation is not executed.

images

Comments

Leave a Reply

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