<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:ent="http://www.purl.org/NET/ENT/1.0/" version="2.0">
  <channel>
    <title>Curiouser and Curiouser! on prolog</title>
    <link>http://matt.blogs.it/</link>
    <description>RSS feed for topic prolog</description>
    <copyright>Copyright 2006 Matt Mower. Some rights reserved.</copyright>
    <generator>Squib/0.5.0.381</generator>
    <managingEditor>self@mattmower.com</managingEditor>
    <webMaster>self@mattmower.com</webMaster>
    <language>en-gb</language>
    <item>
      <title>Sweet ruby logic</title>
      <link>http://matt.blogs.it/entries/00002429.html</link>
      <pubDate>Mon, 30 Oct 2006 09:50:52 +0000</pubDate>
      <description>&lt;p&gt;One of my on-again, off-again, learning projects over the last couple of months has been the Prolog programming language. It can be a bit of a brain-teaser because unlike languages like Java or Ruby where you write each step of how a program goes about solving some problem, in Prolog you give the program a set of rules and a set of beginning facts and it deduces the solution itself (if it can).&lt;/p&gt;

&lt;p&gt;Here's an example Prolog program:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;fallible( X ) :- man( X ).
man( socrates ).
?- fallible( socrates ).
yes
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In Ruby this might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Object
    def fallible?
        false
    end
end

class Man
    def fallible?
        true
    end
end

socrates = Man.new
puts socrates.fallbile?
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Prolog doesn't have to worry too much about how things get done, it just sort of does them. Once you start grokking it, it's very elegant.&lt;/p&gt;

&lt;p&gt;My biggest complaint is the lack of a stylish Prolog environment on MacOSX. I've tried XPG but found it too buggy (in particular it doesn't handle infinite recursion well) and SWI-Prolog. SWI-Prolog is better but it's X and, well, it's just not Mac'ish.&lt;/p&gt;

&lt;p&gt;What lies behind my desire to learn Prolog is the ability to build hybrid applications which use Ruby (or maybe Objective-C) where it makes sense, generating declarative Prolog sub-programs to solve problems as necessary.&lt;/p&gt;

&lt;p&gt;So I was very interested to read about Mauricio Fernandez &lt;a href="http://eigenclass.org/hiki.rb/tag:eigenclass.org,2006-10-28:80/hiki.rb/tiny+prolog+in+ruby-00000000"&gt;experiments with a Ruby implementation called tiny-prolog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now the Ruby example might look something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;fallible[:X] &amp;lt;&amp;lt;= man[:X]
man[:socrates].fact
query fallible[:socrates]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Not quite as nice as the Prolog version but a step forwards none the less.&lt;/p&gt;</description>
      <guid isPermaLink="true">http://matt.blogs.it/entries/00002429.html</guid>
      <ent:cloud ent:href="http://matt.blogs.it/topics/">
      </ent:cloud>
    </item>
  </channel>
</rss>
