Concatenating two lists’ means adding the elements of the second list after the first one. For example, if we have a list with elements [a,b,c,d] and another list with elements [e,f,g,h], then the concatenated list will have elements [a,b,c,d,e,f,g,h].

To implement list_concat predicate in Prolog, add the following lines in kb5.pl file and execute the instructions shown in Figure.

Remember that,

  • list_concat() takes first list, second list, and the concatenated. There are two observations here.
  • If the first list is empty, and second list is L, then the concatenated list will be L.
  • If the first list is not empty, then [Head|Tail] of first list, concatenate Tail with second list recursively, and store into new list in the form, [Head|New List].
images
images

Comments

Leave a Reply

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