{"id":413,"date":"2011-07-17T20:57:49","date_gmt":"2011-07-17T12:57:49","guid":{"rendered":"http:\/\/gergely.imreh.net\/blog\/?p=413"},"modified":"2011-07-17T20:57:49","modified_gmt":"2011-07-17T12:57:49","slug":"language-of-the-month-prolog","status":"publish","type":"post","link":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/","title":{"rendered":"Language of the Month: Prolog"},"content":{"rendered":"<p>New month, new programming language to learn, the 3rd one in this series. So the repertoire so far contains:<\/p>\n<ul>\n<li>May: <a title=\"Language of the Month: Scala\" href=\"http:\/\/gergely.imreh.net\/blog\/2011\/05\/language-of-the-month-scala\/\" target=\"_blank\">Scala<\/a><\/li>\n<li>June: <a title=\"Language of the Month: Lua\" href=\"http:\/\/gergely.imreh.net\/blog\/2011\/06\/language-of-the-month-lua\/\" target=\"_blank\">Lua<\/a><\/li>\n<li>July: Prolog<\/li>\n<\/ul>\n<h2>Prolog<\/h2>\n<p>It is again a very different choice, logic programming. Been playing with it for the last two weeks or so, and it really makes me think differently about programming and programs. Logic and complex thinking was always a favorite past-time of me (e.g. solving puzzles and such), but only now I realized that I do have a lot to practice in this area.<\/p>\n<p>Prolog is also one of the older languages (feels like a &#8220;classmate&#8221; of Lisp and Fortran) so it was the first language in the series where I could actually go to a library, take out some books to learn it, and that book wasn&#8217;t hopelessly out of date (try to do the same thing with Python or Ruby&#8230;). Since these books were also written by academics and not necessarily computer scientists, their whole approach is different, in a way more curious, though probably less practical.<\/p>\n<p>In the end, I think what I would like to gain is a tool that I can use to attack problems that are intractable or at least very difficult in other languages.<\/p>\n<h3>Start<\/h3>\n<p>One of the first thing I found hard to figure out was how to actually run a program. So in a nutshell: even if most of the interaction is within an interpreter-like environment, all the basics have to be prepared in a file and loaded.<\/p>\n<p>E.g. I prepare a file like this (based on Ender&#8217;s Game), call it <strong>ender.pl<\/strong>:<\/p>\n<pre lang=\"prolog\">%% Genealogy of Ender's Game.\r\n% Facts\r\nmale(ender).\r\nmale(peter).\r\nmale('john paul').\r\nfemale(valentine).\r\nfemale(theresa).\r\n\r\nparent('john paul', ender).\r\nparent('john paul', peter).\r\nparent('john paul', valentine).\r\nparent(theresa, ender).\r\nparent(theresa, peter).\r\nparent(theresa, valentine).\r\n\r\n% Predicates\r\nfather(X, Y) :-\r\n\tmale(X),\r\n\tparent(X, Y).\r\nmother(X, Y) :-\r\n\tfemale(X),\r\n\tparent(X, Y).\r\n\r\nsibling(X, Y) :-\r\n\tfather(F, X), mother(M, X),\r\n\tfather(F, Y), mother(M, Y),\r\n\tX \\= Y.\r\nbrother(X, Y) :-\r\n\tmale(X),\r\n\tsibling(X, Y).\r\nsister(X, Y) :-\r\n\tfemale(X),\r\n\tsibling(X, Y).<\/pre>\n<p>Then starting Prolog I can load the file with the <strong>[&#8216;ender.pl&#8217;].<\/strong> form, and ask questions like who is Ender&#8217;s sister? Who are Theresa&#8217;s kids? Who are Peter&#8217;s siblings?<\/p>\n<pre lang=\"Prolog\">?- ['ender.pl'].\r\n% ender.pl compiled 0.00 sec, 144 bytes\r\ntrue.\r\n\r\n?- sister(Sis, ender).\r\nSis = valentine ;\r\nfalse.\r\n\r\n?- mother(theresa, Kid).\r\nKid = ender ;\r\nKid = peter ;\r\nKid = valentine.\r\n\r\n?- sibling(peter, X).\r\nX = ender ;\r\nX = valentine ;\r\nfalse.<\/pre>\n<p>Well, this is laughably simple, and I&#8217;m beyond this already, but it&#8217;s good for a first illustration.<\/p>\n<p>By the way, it looks like 90% of elementary Prolog examples use family trees (Nordic or Greek gods, literary, real families&#8230;)<\/p>\n<p>Now let&#8217;s get in there and learn some more stuff&#8230;<\/p>\n<h2>Links<\/h2>\n<h3>Tutorials &amp; Info<\/h3>\n<ul>\n<li><a title=\"A Short Tutorial on Prolog\" href=\"http:\/\/www.doc.gold.ac.uk\/~mas02gw\/prolog_tutorial\/prologpages\/\" target=\"_blank\">A Short Tutorial on Prolog<\/a><\/li>\n<li><a title=\"Adventure in Prolog homepage\" href=\"http:\/\/www.amzi.com\/AdventureInProlog\/index.php\" target=\"_blank\">Adventure in Prolog<\/a><\/li>\n<li><a title=\"Lecture 13 in the Lecture Series on Artificial Intelligence by Prof. P. Dasgupta, \" href=\"http:\/\/www.youtube.com\/watch?v=jySpg72Vbc4\" target=\"_blank\">Logic Programing lecture<\/a>\u00a0and <a title=\"Lecture 14 in Lecture Series on Artificial Intelligence by Prof. P. Dasgupta\" href=\"http:\/\/www.youtube.com\/watch?v=iJhtgWAGUAQ\" target=\"_blank\">Prolog Programming<\/a>\u00a0(videos)<\/li>\n<li><a title=\"Prolog on Wikipedia\" href=\"http:\/\/en.wikipedia.org\/wiki\/Prolog\" target=\"_blank\">Prolog on Wikipedia<\/a><\/li>\n<\/ul>\n<h3>Books<\/h3>\n<ul>\n<li><a title=\"The Art of Prolog book homepage\" href=\"http:\/\/mitpress.mit.edu\/catalog\/item\/default.asp?ttype=2&amp;tid=8327\" target=\"_blank\">The Art of Prolog<\/a><\/li>\n<\/ul>\n<h3>Compilers<\/h3>\n<ul>\n<li><a title=\"SWI Prolog homepage\" href=\"http:\/\/www.swi-prolog.org\/\" target=\"_blank\">SWI Prolog<\/a><\/li>\n<li><a title=\"GNU Prolog homepage\" href=\"http:\/\/www.gprolog.org\/\" target=\"_blank\">GNU Prolog<\/a><\/li>\n<li><a title=\"Yet Another Prolog homepage\" href=\"http:\/\/www.dcc.fc.up.pt\/~vsc\/Yap\/\" target=\"_blank\">Yet Another Prolog (YAP)<\/a><\/li>\n<\/ul>\n<h3>Code<\/h3>\n<ul>\n<li><a title=\"Solve Einstein\u2019s Riddle using Prolog\" href=\"http:\/\/www.baptiste-wicht.com\/2010\/09\/solve-einsteins-riddle-using-prolog\/\" target=\"_blank\">Einstein&#8217;s Riddle in Prolog<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>New month, new programming language to learn, the 3rd one in this series. So the repertoire so far contains: May: Scala June: Lua July: Prolog Prolog It is again a very different choice, logic programming. Been playing with it for the last two weeks or so, and it really makes me think differently about programming [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[44,51],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-prog","tag-lotm","tag-prolog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Language of the Month: Prolog - ClickedyClick<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Language of the Month: Prolog - ClickedyClick\" \/>\n<meta property=\"og:description\" content=\"New month, new programming language to learn, the 3rd one in this series. So the repertoire so far contains: May: Scala June: Lua July: Prolog Prolog It is again a very different choice, logic programming. Been playing with it for the last two weeks or so, and it really makes me think differently about programming [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/\" \/>\n<meta property=\"og:site_name\" content=\"ClickedyClick\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/gergely.imreh\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/gergely.imreh\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-17T12:57:49+00:00\" \/>\n<meta name=\"author\" content=\"Gergely Imreh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@imrehg\" \/>\n<meta name=\"twitter:site\" content=\"@imrehg\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gergely Imreh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/\"},\"author\":{\"name\":\"Gergely Imreh\",\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/#\\\/schema\\\/person\\\/42391e2ae52c8ed76b37be509a5707b0\"},\"headline\":\"Language of the Month: Prolog\",\"datePublished\":\"2011-07-17T12:57:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/\"},\"wordCount\":400,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/#\\\/schema\\\/person\\\/42391e2ae52c8ed76b37be509a5707b0\"},\"keywords\":[\"lotm\",\"prolog\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/\",\"url\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/\",\"name\":\"Language of the Month: Prolog - ClickedyClick\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/#website\"},\"datePublished\":\"2011-07-17T12:57:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/2011\\\/07\\\/language-of-the-month-prolog\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Language of the Month: Prolog\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/\",\"name\":\"ClickedyClick\",\"description\":\"Life in real, complex and digital.\",\"publisher\":{\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/#\\\/schema\\\/person\\\/42391e2ae52c8ed76b37be509a5707b0\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/#\\\/schema\\\/person\\\/42391e2ae52c8ed76b37be509a5707b0\",\"name\":\"Gergely Imreh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g\",\"caption\":\"Gergely Imreh\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g\"},\"description\":\"Physicist, hacker. Enjoys avant-guarde literature probably a bit too much. Open source advocate and contributor, both for software and hardware. Follow these posts on the Fediverse by @gergely@gergely.imreh.net\",\"sameAs\":[\"https:\\\/\\\/gergely.imreh.net\\\/\",\"https:\\\/\\\/www.facebook.com\\\/gergely.imreh\",\"https:\\\/\\\/www.instagram.com\\\/imrehg\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/gergelyimreh\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@GergelyImreh\"],\"url\":\"https:\\\/\\\/gergely.imreh.net\\\/blog\\\/author\\\/gergely\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Language of the Month: Prolog - ClickedyClick","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/","og_locale":"en_GB","og_type":"article","og_title":"Language of the Month: Prolog - ClickedyClick","og_description":"New month, new programming language to learn, the 3rd one in this series. So the repertoire so far contains: May: Scala June: Lua July: Prolog Prolog It is again a very different choice, logic programming. Been playing with it for the last two weeks or so, and it really makes me think differently about programming [&hellip;]","og_url":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/","og_site_name":"ClickedyClick","article_publisher":"https:\/\/www.facebook.com\/gergely.imreh","article_author":"https:\/\/www.facebook.com\/gergely.imreh","article_published_time":"2011-07-17T12:57:49+00:00","author":"Gergely Imreh","twitter_card":"summary_large_image","twitter_creator":"@imrehg","twitter_site":"@imrehg","twitter_misc":{"Written by":"Gergely Imreh","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/#article","isPartOf":{"@id":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/"},"author":{"name":"Gergely Imreh","@id":"https:\/\/gergely.imreh.net\/blog\/#\/schema\/person\/42391e2ae52c8ed76b37be509a5707b0"},"headline":"Language of the Month: Prolog","datePublished":"2011-07-17T12:57:49+00:00","mainEntityOfPage":{"@id":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/"},"wordCount":400,"commentCount":5,"publisher":{"@id":"https:\/\/gergely.imreh.net\/blog\/#\/schema\/person\/42391e2ae52c8ed76b37be509a5707b0"},"keywords":["lotm","prolog"],"articleSection":["Programming"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/","url":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/","name":"Language of the Month: Prolog - ClickedyClick","isPartOf":{"@id":"https:\/\/gergely.imreh.net\/blog\/#website"},"datePublished":"2011-07-17T12:57:49+00:00","breadcrumb":{"@id":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gergely.imreh.net\/blog\/2011\/07\/language-of-the-month-prolog\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gergely.imreh.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Language of the Month: Prolog"}]},{"@type":"WebSite","@id":"https:\/\/gergely.imreh.net\/blog\/#website","url":"https:\/\/gergely.imreh.net\/blog\/","name":"ClickedyClick","description":"Life in real, complex and digital.","publisher":{"@id":"https:\/\/gergely.imreh.net\/blog\/#\/schema\/person\/42391e2ae52c8ed76b37be509a5707b0"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gergely.imreh.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/gergely.imreh.net\/blog\/#\/schema\/person\/42391e2ae52c8ed76b37be509a5707b0","name":"Gergely Imreh","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g","caption":"Gergely Imreh"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/1d5be311c5d616a3f4c7dfbc6b736ec817d2508b8c420ec29edb950d33fb4946?s=96&d=retro&r=g"},"description":"Physicist, hacker. Enjoys avant-guarde literature probably a bit too much. Open source advocate and contributor, both for software and hardware. Follow these posts on the Fediverse by @gergely@gergely.imreh.net","sameAs":["https:\/\/gergely.imreh.net\/","https:\/\/www.facebook.com\/gergely.imreh","https:\/\/www.instagram.com\/imrehg\/","https:\/\/www.linkedin.com\/in\/gergelyimreh\/","https:\/\/www.youtube.com\/@GergelyImreh"],"url":"https:\/\/gergely.imreh.net\/blog\/author\/gergely\/"}]}},"_links":{"self":[{"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":18,"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":2277,"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions\/2277"}],"wp:attachment":[{"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gergely.imreh.net\/blog\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}