{"id":3802,"date":"2024-09-07T18:25:03","date_gmt":"2024-09-07T18:25:03","guid":{"rendered":"https:\/\/workhouse.sweetdishy.com\/?p=3802"},"modified":"2024-09-07T18:25:04","modified_gmt":"2024-09-07T18:25:04","slug":"lists-in-prolog","status":"publish","type":"post","link":"https:\/\/workhouse.sweetdishy.com\/index.php\/2024\/09\/07\/lists-in-prolog\/","title":{"rendered":"Lists in Prolog"},"content":{"rendered":"\n<p id=\"Arti00011881\">List is a simple data structure that can contain any number of items. Individual items of a list are placed within square brackets ([]). For example, a list of students, we will write, [\u2018Manya\u2019, \u2018Amyra\u2019,\u2019Raman\u2019,\u2019John\u2019,\u2019Zeenat\u2019]. We can also define an empty list by writing, a Prolog atom, [].<\/p>\n\n\n\n<p id=\"Arti00011882\">A list with element(s) have two important things,<\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"Arti00011883\">\n<li>Head which is the first item of the list<\/li>\n\n\n\n<li>Tail that is the remaining part of the list<\/li>\n<\/ul>\n\n\n\n<p id=\"Arti00011886\">In the list, [\u2018Manya\u2019,\u2019Amyra\u2019,\u2019Raman\u2019,\u2019John\u2019,\u2019Zeenat\u2019], \u2018Manya\u2019 is the head of the list. Tail is another list consisting of [\u2018Amyra\u2019,\u2019Raman\u2019,\u2019John\u2019,\u2019Zeenat\u2019].<\/p>\n\n\n\n<p id=\"Arti00011887\">Note that if we have a list, L = [a, b, c]. Then, Tail = [b, c]<\/p>\n\n\n\n<p id=\"Arti00011888\">This can be also written as L = [ a | Tail].<\/p>\n\n\n\n<p id=\"Arti00011889\">Here, the vertical bar (|) separates the head and tail parts.<\/p>\n\n\n\n<p id=\"Arti00011890\"><a><\/a>List can also be represented as,<\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"Arti00011891\">\n<li>[a, b, c] = [a, | [b, c] ]<\/li>\n\n\n\n<li>[a, b, c] = [a, b | [c] ]<\/li>\n\n\n\n<li>[a, b, c] = [a, b, c | [ ] ]<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00011895\"><strong>Basic Operations on Lists<\/strong><\/h4>\n\n\n\n<p id=\"Arti00011896\">Table lists some operations that can be performed on lists in Prolog.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p578-1.png\" alt=\"images\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00011899\"><strong>Membership Operation<\/strong><\/h4>\n\n\n\n<p id=\"Arti00011900\">To check membership, we define a predicate, list_member(X,L) that will consider two things. If X is a member of a list, then either X is head of the list or is a member of the tail of the list.<\/p>\n\n\n\n<p id=\"Arti00011901\">To implement this predicate, create a new file in text editor, write the following lines of code in it and save it as kb5.pl.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p578.png\" alt=\"images\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p578-2.png\" alt=\"images\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>List is a simple data structure that can contain any number of items. Individual items of a list are placed within square brackets ([]). For example, a list of students, we will write, [\u2018Manya\u2019, \u2018Amyra\u2019,\u2019Raman\u2019,\u2019John\u2019,\u2019Zeenat\u2019]. We can also define an empty list by writing, a Prolog atom, []. A list with element(s) have two important [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[464],"tags":[],"class_list":["post-3802","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-language-prolog"],"jetpack_featured_media_url":"https:\/\/workhouse.sweetdishy.com\/wp-content\/uploads\/2024\/08\/programming.png","_links":{"self":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/comments?post=3802"}],"version-history":[{"count":1,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3802\/revisions"}],"predecessor-version":[{"id":3803,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3802\/revisions\/3803"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media\/3341"}],"wp:attachment":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media?parent=3802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/categories?post=3802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/tags?post=3802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}