<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Logtalking</title>
	<atom:link href="http://blog.logtalk.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.logtalk.org</link>
	<description>Logtalk development happy moments, hurdles, and dreams</description>
	<lastBuildDate>Fri, 19 Aug 2011 23:20:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WG17 changes course</title>
		<link>http://blog.logtalk.org/2011/04/happy-april-fools-day/</link>
		<comments>http://blog.logtalk.org/2011/04/happy-april-fools-day/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 21:49:36 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[prolog]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=630</guid>
		<description><![CDATA[This just in: WG17 changes course Tired of being cursed by all for standardization problems and mishaps, the next ISO Prolog Core standard revision will mandate: - Forward-chaining inference mechanism. Stated reason: you cannot move Prolog forward doing backward reasoning. - Replacement of stream-based input/output with revamped, time-proved, Edinburgh-style input/output. Highlights: see_what/1 and told_you_so/0 built-in [...]]]></description>
			<content:encoded><![CDATA[<p>This just in: WG17 changes course</p>
<p>Tired of being cursed by all for standardization problems and mishaps, the next ISO Prolog Core standard revision will mandate:</p>
<p>- Forward-chaining inference mechanism. Stated reason: you cannot move Prolog forward doing backward reasoning.</p>
<p>- Replacement of stream-based input/output with revamped, time-proved, Edinburgh-style input/output. Highlights: <code>see_what/1</code> and <code>told_you_so/0</code> built-in predicates for DWIM user-friendly semantics.</p>
<p>- New character escape <code>0'\q</code> unexpectedly quits Prolog for those embarrassing programming moments.</p>
<p>- Due to all controversy regarding <code>char_conversion/2</code>, from now on all standards will be published in Esperanto.</p>
<p>- Attempting printing of cyclic terms will endlessly print the lyrics of &#8220;99 bottles of beer on the wall&#8221;.</p>
<p>- New operator class <code>yfy</code> for decomposing operands.</p>
<p>- Singleton variable report by <code>read_term/3</code> is deprecated as it&#8217;s not politically correct to complain about a variable choice of life-style. In addition, for privacy reasons, the <code>variable_names/1</code> option is also deprecated.</p>
<p>- New value for the <code>unknown</code> flag, <code>true</code>, provides a sharp decrease on the number of &#8220;<code>no</code>&#8220;s reported by Prolog interpreters. Specially relevant in educational environments, it will hopefully contribute to make the language more attractive to students.</p>
<p>- Database built-in predicates are enhanced with an optional argument for cloud computing. Handy for hiding your dirty programming tricks.</p>
<p>- The de facto standard <code>freeze/2</code> predicate is added to the standard but with an extra argument that allows the user to specify a time-out value, freeing the goal to fulfill its destiny.</p>
<p>- Further details are still being worked out but stay tuned.</p>
<p>Hoping that no one here is humor-impaired, Happy April Fools&#8217; Day :-)</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2011%2F04%2Fhappy-april-fools-day%2F&amp;title=WG17%20changes%20course" id="wpa2a_2">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2011/04/happy-april-fools-day/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A more sane implementation of the term-expansion mechanism</title>
		<link>http://blog.logtalk.org/2011/03/a-more-sane-implementation-of-the-term-expansion-mechanism/</link>
		<comments>http://blog.logtalk.org/2011/03/a-more-sane-implementation-of-the-term-expansion-mechanism/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 00:38:47 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[prolog]]></category>
		<category><![CDATA[term-expansion]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=626</guid>
		<description><![CDATA[One of the oldest and more useful feature found in most Prolog compilers is the term-expansion mechanism. Acting as a souped-up pre-processor, defining term- and goal expansion clauses allows us to rewrite terms and goals as their are read from a source file and apply all kinds of transformations. This made term-expansion the preferred mechanism [...]]]></description>
			<content:encoded><![CDATA[<p>One of the oldest and more useful feature found in most Prolog compilers is the term-expansion mechanism. Acting as a souped-up pre-processor, defining term- and goal expansion clauses allows us to rewrite terms and goals as their are read from a source file and apply all kinds of transformations. This made term-expansion the preferred mechanism for implementing all sorts of extensions to Prolog.</p>
<p>You may be wondering if the Logtalk compiler is also implemented using the term-expansion mechanism. The answer is no. One of the main reasons is that the term-expansion mechanism is not implemented by all Prolog compilers. Among those that do implement term-expansion, there are also some minor (and not so minor) syntax and semantics differences. The real trouble with term-expansion results, however, from its usual implementation and usage patterns, combined with module features, not from those portability issues.</p>
<p>The usual pattern when implementing some Prolog extension using the term-expansion mechanism is to define a module, relying on term- and goal-expansion clauses to compile to standard Prolog code the syntactic elements defined by the extension. As the recommended way of using modules is to simply use a <code>use_module/1</code> directive to make the module resources available in your current context (how convenient and easy is to shoot yourself in the foot&#8230; but I digress), the <code>term_expansion/2</code> and <code>goal_expansion/2</code> predicates are declared as multifile predicates, with the clauses ending up either on the <code>user</code> module or on a special system module. Either way is fine until you try to use more than one module that defines <code>term_expansion/2</code> clauses. The Prolog compiler will try <code>term_expansion/2</code> clauses until it finds one that succeeds for the term being expanded or until there are no more clauses left to try (the <code>goal_expansion/2</code> predicate, however, is called recursively until no more goal-expansion clauses apply). Assuming that no two Prolog modules want to expand the same term (one can always hope), there should no problem. Sure, there might be a performance issue due to trying and failing <code>term_expansion/2</code> clauses until the correct one is selected. But what happens if two modules compete for expanding the same term? Say, the <code>end_of_file</code> term. Well, if the module developers are not aware of the problem, one of them will likely lose. Each one? That will depend on the modules loading order. The usual workaround is to define <code>term_expansion/2</code> clauses that perform their magic using side-effects to record the results and fail when done. The failure leads to backtracking, giving other <code>term_expansion/2</code> clauses a chance to be applied. Ugliness of using side-effects apart, there is a more sane way of implementing and using the term-expansion mechanism.</p>
<p>One of the advantages of not being first (to design and try a new mechanism) is that you can learn from both the successes and mistakes of others before you. The implementation of term-expansion in Logtalk differs from the implementation found on most Prolog compilers in two crucial aspects.</p>
<p>First, Logtalk doesn&#8217;t support using the term- and goal expansion clauses defined in an object (or source file) to expand the object (or source file) itself. It&#8217;s already bad enough that some predicate directives must precede the compilation of calls to those predicates. But having the result of the compilation of an object (or source file) depend on the order of the predicate definitions in the same object (or source file) feels plain wrong. Specially as it&#8217;s an exception to the way both Logtalk and Prolog compilers work. Just imagine being forced to define all predicates called by a predicate before it could be defined. It will be painful. It would also be impossible in some cases. Yet, well know Prolog extensions do just that, throwing portability down the drain (not all Prolog compilers make predicate definitions visible and usable, as soon as they are compiled, without waiting for the rest of the source file to be compiled&#8230;).</p>
<p>Second, term- and goal-expansion clauses are defined local to the object where they are defined. It&#8217;s possible to add those clauses to the pseudo-object <code>user</code> (Logtalk supports multifile object predicates). But that is neither necessary or advised. Do we really want to put all our eggs&#8230; err&#8230; term-expansion hooks in the same basket?</p>
<p>So, what&#8217;s the magic incantation to use term-expansion in Logtalk? Easy. Objects containing clauses for the term- and goal expansion predicates are known as hook objects. When compiling a source file, you use a compiler option to state which hook object should be used to term-expand the source file. For example, assuming a hook object named <code>my_expansion</code> we could write:</p>
<blockquote>
<pre>| ?- logtalk_load(source_file, [hook(my_expansion)]).</pre>
</blockquote>
<p>This compiler option also provides a nice solution for combining different hook objects in order to expand the same source file. You simply define another hook object that calls the term- and goal-expansion predicates defined in the base hook objects. This allows fine control on how the different expansions will work together. For example, we can define a pipeline of goal-expansions. Or apply all term-expansions in parallel and combine the resulting terms. For some sample code, check the <code>expanding</code> example in the current Logtalk distribution. Or browse the example source code on-line:</p>
<blockquote><p>
<a href="http://trac.logtalk.org/browser/trunk/examples/expansion">http://trac.logtalk.org/browser/trunk/examples/expansion</a>
</p></blockquote>
<p>Even when a source file is to be expanded using a single hook object, we can be ensured that the compilation time will not be adversely affected by other hook objects that might be loaded at the time of the compilation. The code also becomes easier to debug as only the relevant term-expansion clauses will be in focus.</p>
<p>P.S. It&#8217;s worth noting that the Logtalk term-expansion implementation and recommended usage patterns can be easily adopted by Prolog module systems. In that regard, it&#8217;s also worth noting that some Prolog compilers, e.g. SICStus Prolog and Ciao Prolog, already include improved implementations of term-expansion mechanisms.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2011%2F03%2Fa-more-sane-implementation-of-the-term-expansion-mechanism%2F&amp;title=A%20more%20sane%20implementation%20of%20the%20term-expansion%20mechanism" id="wpa2a_4">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2011/03/a-more-sane-implementation-of-the-term-expansion-mechanism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding guidelines and the spaces-versus-tabs holy war</title>
		<link>http://blog.logtalk.org/2011/03/coding-guidelines-and-the-spaces-versus-tabs-holy-war/</link>
		<comments>http://blog.logtalk.org/2011/03/coding-guidelines-and-the-spaces-versus-tabs-holy-war/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 02:11:35 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[prolog]]></category>
		<category><![CDATA[coding guidelines]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=623</guid>
		<description><![CDATA[Logtalk, like most programming languages, defines a set of coding guidelines that aim to improve the quality and readability of source code: http://trac.logtalk.org/wiki/CodingGuidelines These coding guidelines are also mandatory for contributions to the Logtalk distribution. Most guidelines in the above document are pretty consensual but one of them, source code layout and indentation, always stirs [...]]]></description>
			<content:encoded><![CDATA[<p>Logtalk, like most programming languages, defines a set of coding guidelines that aim to improve the quality and readability of source code:</p>
<blockquote><p>
<a href="http://trac.logtalk.org/wiki/CodingGuidelines">http://trac.logtalk.org/wiki/CodingGuidelines</a>
</p></blockquote>
<p>These coding guidelines are also mandatory for contributions to the Logtalk distribution. Most guidelines in the above document are pretty consensual but one of them, source code layout and indentation, always stirs a lot of discussion:</p>
<blockquote><p>
Format your source file using tabs, not spaces.
</p></blockquote>
<p>Search the web and you can easily find passionate texts defending the use of either tabs or spaces for source code layout and indentation. Recently, I was commenting on a <a href="http://arxiv.org/abs/0911.2899">paper</a> on Prolog coding guidelines that stated:</p>
<blockquote><p>
2.1 Indent with spaces instead of tabs.</p>
<p>You cannot normally predict how tabs will be set in the editors and browsers others will use on your code. Moreover, mixing tabs and spaces makes searches and substitutions more problematic. All in all, it is better not to use tabs altogether: almost any editor can be set to substitute spaces for tabs automatically when saving your file.
</p></blockquote>
<p>Take the first sentence. It completely misses the point of using tabs instead of spaces. Try this. Open any of the many examples distributed with Logtalk in your favorite text editor. The example source code is formatted using tabs. Next go to your text editor preferences and adjust the tab size to your liking. I prefer a tab size equivalent to 4 spaces. You may prefer a tab size equivalent to 2 spaces. Or 3 spaces. Or 6 spaces. No matter your choice, the code will remain perfectly indented. That means that I&#8217;m not imposing on you my indentation preferences. If someone gives you a file indented using spaces, say, where an indentation level is 2 spaces, and you prefer to use 4 spaces, your preference will be ignored. You will need to edit the file, i.e. change it, even if only for you to feel comfortable reading/studying the source code.</p>
<p>If you think that my argument is only meaningful for text editors but not for browsers, well, think again. I have written (and tested!) support for syntax highlight of Logtalk source code for Pygments, GeSHi, Highlight, Source-highlight, and SyntaxHighlighter. If you&#8217;re publishing source code on a web page, a blog, or a wiki, chances are that you will be using one of these syntax highlighters. As you already guessed, they allow you to set your tab preferences. Never found a problem due to the use of tabs instead of spaces.</p>
<p>I have also written (and tested!) Logtalk syntax highlight support for several text editors, including TextMate, SubEthaEdit, Emacs, Vim, Kate, Gedit (i.e. GtkSourceView), NEdit, and jEdit. Again, never found a problem due to the use of tabs instead of spaces. This, I concede, may not have always been true in the past but, nowadays, using spaces for indentation is just a big waste of space. And obnoxious to all people you may share your code with that don&#8217;t necessarily share with you the same preferences for the size of an indentation level.</p>
<p>As this post is about a holy war, it&#8217;s mandatory and good netiquette that I finnish it with a suitable insult or inflammatory remark to the other side. So, death to the tab infidels! May your spacebar burn in hell!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2011%2F03%2Fcoding-guidelines-and-the-spaces-versus-tabs-holy-war%2F&amp;title=Coding%20guidelines%20and%20the%20spaces-versus-tabs%20holy%20war" id="wpa2a_6">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2011/03/coding-guidelines-and-the-spaces-versus-tabs-holy-war/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Writing unit tests in Logtalk</title>
		<link>http://blog.logtalk.org/2011/03/writing-unit-tests-in-logtalk/</link>
		<comments>http://blog.logtalk.org/2011/03/writing-unit-tests-in-logtalk/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 00:49:22 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=622</guid>
		<description><![CDATA[Logtalk provides simple but portable support for writing unit tests. This support is provided by a library object, lgtunit, inspired on the works of Joachim Schimpf (ECLiPSe library test_util) and Jan Wielemaker (SWI-Prolog plunit package). You can load it using the goal: &#124; ?- logtalk_load(library(lgtunit)). The interface of the lgtunit object is quite simple and [...]]]></description>
			<content:encoded><![CDATA[<p>Logtalk provides simple but portable support for writing unit tests. This support is provided by a library object, <code>lgtunit</code>, inspired on the works of Joachim Schimpf  (ECLiPSe library <code>test_util</code>) and Jan Wielemaker (SWI-Prolog <code>plunit</code> package). You can load it using the goal:</p>
<blockquote>
<pre>| ?- logtalk_load(library(lgtunit)).</pre>
</blockquote>
<p>The interface of the <code>lgtunit</code> object is quite simple and can be found e.g here:</p>
<blockquote><p>
<a href="http://logtalk.org/library/lgtunit_0.html">http://logtalk.org/library/lgtunit_0.html</a>
</p></blockquote>
<p>Most of the examples found on the current Logtalk distribution include a set of unit tests, together with a handy loader file named <code>tester.lgt</code>. Typically, this loader file loads the code you want to test, the unit test framework, the unit tests themselves, and send a <code>run/0</code> message to the unit test objects. Check, for instance, the example:</p>
<blockquote><p>
<a href="http://trac.logtalk.org/browser/trunk/examples/people">http://trac.logtalk.org/browser/trunk/examples/people</a>
</p></blockquote>
<p>In order for you to write your own unit tests, start by defining objects extending the <code>lgtunit</code> object. These objects must be compiled using the option <code>hook(lgtunit)</code>. For example:</p>
<blockquote>
<pre>| ?- logtalk_load(my_tests, [hook(lgtunit)]).</pre>
</blockquote>
<p>After successful compilation and loading of your unit test objects, you can run them by typing:</p>
<blockquote>
<pre>| ?- my_tests::run.</pre>
</blockquote>
<p>Logtalk unit tests can be written using any of three different dialects. The most simple dialect is:</p>
<blockquote>
<pre>test(Test) :- Goal.</pre>
</blockquote>
<p>This dialect allows the specification of tests that are expected to succeed. Tests that are expected to fail can be written by using the <code>\+/1</code> built-in predicate. However, tests that are expected to throw an error cannot be specified. A second dialect overcomes this restriction:</p>
<blockquote><pre>succeeds(Test) :- Goal.
fails(Test) :- Goal.
throws(Test, Error) :- Goal.</pre>
</blockquote>
<p>This is a straightforward dialect. For <code>succeeds/1</code> tests, <code>Goal</code> is expected to succeed. For <code>fails/1</code> tests, <code>Goal</code> is expected to fail. For <code>throws/2</code> tests, <code>Goal</code> is expected to throw <code>Error</code>. A third supported dialect is:</p>
<blockquote><pre>test(Test, Outcome) :- Goal.</pre>
</blockquote>
<p>In this case, <code>Outcome</code> can be the atom <code>true</code>, the atom <code>fail</code>, or the exception term that the test is expected to throw. In all cases, <code>Test</code> is an atom, uniquely identifying a test. Simply use the dialect that is the best fit for your application.</p>
<p>That&#8217;s all. Happy testing!</p>
<p><strong>Note:</strong> when using the <code>&lt;&lt;/2</code> control construct to access and test an object internal predicates, make sure that the objects are compiled with the <code>context_switching_calls</code> flag set to <code>allow</code>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2011%2F03%2Fwriting-unit-tests-in-logtalk%2F&amp;title=Writing%20unit%20tests%20in%20Logtalk" id="wpa2a_8">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2011/03/writing-unit-tests-in-logtalk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prolog modules madness II</title>
		<link>http://blog.logtalk.org/2010/12/prolog-modules-madness-ii/</link>
		<comments>http://blog.logtalk.org/2010/12/prolog-modules-madness-ii/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 16:42:41 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[prolog]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=617</guid>
		<description><![CDATA[Try the following experiment in a Prolog compiler with a module system. Define a simple module containing a simple meta-predicate that tests its meta-argument, writing an error message if it&#8217;s uninstantiated: :- module(m, [mp/1]). &#160; :- meta_predicate(mp(0)). &#160; mp(Goal) :- ( var(Goal) -&#62; write(error) ; write(passed) ). Compile and load the code above and we&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Try the following experiment in a Prolog compiler with a module system. Define a simple module containing a simple meta-predicate that tests its meta-argument, writing an error message if it&#8217;s uninstantiated:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;"><span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">module</span>(m, [mp<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">1</span>]).
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">meta_predicate</span>(mp(<span style="color: #430000;">0</span>)).
&nbsp;
mp(<span style="color: #848484;">Goal</span>) <span style="color: #000000;">:-</span>
    (    <span style="color: #9d4f37;">var</span>(<span style="color: #848484;">Goal</span>) <span style="color: #666666;font-weight: bold;">-&gt;</span>
         <span style="color: #9d4f37;">write</span>(error)
    <span style="color: #666666;font-weight: bold;">;</span>    <span style="color: #9d4f37;">write</span>(passed)
    ).</pre></div></div>

</blockquote>
<p>Compile and load the code above and we&#8217;re ready for a quick test. This is the result you get with current versions of SICStus Prolog, SWI-Prolog, and YAP:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">| ?- m:mp(_).
passed
yes</pre></div></div>

</blockquote>
<p>You get this result no matter how you load the module file. You also get this result if you import the module meta-predicate in order to call it without using explicit qualification:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">| ?- mp(_).
passed
yes</pre></div></div>

</blockquote>
<p>Before looking closely for an explanation why we don&#8217;t get an <code>error</code> message instead of a <code>passed</code> message, allow me to show the result you get in Logtalk with the same meta-predicate definition:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;"><span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">object</span>(obj).
&nbsp;
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(mp<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">1</span>).
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">meta_predicate</span>(mp(<span style="color: #430000;">0</span>)).
&nbsp;
    mp(<span style="color: #848484;">Goal</span>) <span style="color: #000000;">:-</span>
        (    <span style="color: #9d4f37;">var</span>(<span style="color: #848484;">Goal</span>) <span style="color: #666666;font-weight: bold;">-&gt;</span>
             <span style="color: #9d4f37;">write</span>(error)
        <span style="color: #666666;font-weight: bold;">;</span>    <span style="color: #9d4f37;">write</span>(passed)
        ).
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">end_object</span>.</pre></div></div>

</blockquote>
<p>After compiling an loading this object, we get:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">| ?- obj::mp(_).
error
yes</pre></div></div>

</blockquote>
<p>Back to the module example. Is the standard <code>var/1</code> built-in predicate broken? Or maybe <code>var/1</code> isn&#8217;t module-aware? Should we blame the <code>meta_predicate/1</code> directive? But we want it in order to be able to call the meta-predicate without qualifying both the call and the meta-arguments(!) when importing the module. At this point, Prolog module pundits are likely loosing their patience and screaming that the solution is to &#8220;correct&#8221; the meta-predicate definition to:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">mp(<span style="color: #848484;">_</span><span style="color: #666666;font-weight: bold;">:</span><span style="color: #848484;">Goal</span>) <span style="color: #000000;">:-</span>
    (    <span style="color: #9d4f37;">var</span>(<span style="color: #848484;">Goal</span>) <span style="color: #666666;font-weight: bold;">-&gt;</span>
         <span style="color: #9d4f37;">write</span>(error)
    <span style="color: #666666;font-weight: bold;">;</span>    <span style="color: #9d4f37;">write</span>(passed)
    ).</pre></div></div>

</blockquote>
<p>With this &#8220;corrected&#8221; definition you now get:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">| ?- m:mp(_).
error
yes</pre></div></div>

</blockquote>
<p>Some will go as far as arguing that, because a simple workaround is available, everything is fine. But one of the main goals of the <code>meta_predicate/1</code> directive is to avoid using explicit qualification (as we are now doing in the meta-predicate clause head) in the first place. Wouldn&#8217;t it be more elegant to make <code>var/1</code> (and other built-in predicates!) module-aware? That would fit nicely with the common argument that modules are a natural solution for encapsulation Prolog code. And would avoid the trouble of adding not only a <code>meta_predicate/1</code> directive but also modifying the meta-predicate definition when moving a meta-predicate to another module. Not to mention that the original, broken module meta-predicate definition is more elegant, straightforward, easier to explain and understand by novice programmers when compared with the &#8220;corrected&#8221; definition, which requires understanding the lower-level details of Prolog modules compilation.</p>
<p><strong>Update:</strong> You may wonder what results you get with other Prolog compilers with modules systems. The problem doesn&#8217;t exist in ECLiPSe as this compiler uses an alternative solution for declaring and defining meta-predicates. The problem also doesn&#8217;t exist in the beta versions of Ciao 1.13 where our first attempt at defining the meta-predicate is also the correct one, working similar to Logtalk in this respect.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2010%2F12%2Fprolog-modules-madness-ii%2F&amp;title=Prolog%20modules%20madness%20II" id="wpa2a_10">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2010/12/prolog-modules-madness-ii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How To Misappropriate and Misrepresent Other People&#8217;s Hard Work in 12 Easy Steps</title>
		<link>http://blog.logtalk.org/2010/06/how-to-misappropriate-and-misrepresent-other-peoples-hard-work-in-12-easy-steps/</link>
		<comments>http://blog.logtalk.org/2010/06/how-to-misappropriate-and-misrepresent-other-peoples-hard-work-in-12-easy-steps/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 03:21:08 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=550</guid>
		<description><![CDATA[Step 1. Work using an alias. Why expose your identity? Step 2. Spend years asking the Logtalk open-source developer to implement everything except the proverbial kitchen sink, while at the same time politely declining to make any significant code contribution to all those features you find critical. After all, you&#8217;re a commercial user, with serious [...]]]></description>
			<content:encoded><![CDATA[<p>
<strong>Step 1.</strong> Work using an alias. Why expose your identity?
</p>
<p>
<strong>Step 2.</strong> Spend years <a href="http://forums.logtalk.org/viewforum.php?f=14">asking</a> the Logtalk open-source developer to implement everything except the proverbial kitchen sink, while at the same time politely declining to make any significant code contribution to all those features you find critical. After all, you&#8217;re a commercial user, with serious business to attend to. No time to fool around. In our example, the wish list includes:
</p>
<ul>
<li>an IDE</li>
<li>a type-checker</li>
<li>a cross-referencer</li>
<li>automatic dependency generation</li>
<li>a bootstrapped implementation</li>
<li>a code coverage tool</li>
<li>a web server</li>
<li>a sockets interface</li>
<li>unit test support (ignoring the existing one)</li>
<li>new documenting tools (as the existing ones don&#8217;t fit your commercial development requirements)</li>
<li>a revamped debugger</li>
<li>&#8230;</li>
</ul>
<p>
<strong>Step 3.</strong> Score hundreds of hours of free support, including on-line and in-situ, from the Logtalk developer. Besides saving you precious development time, you&#8217;re also learning the fine details of the Logtalk implementation, which will be quite handy in later steps.
</p>
<p>
<strong>Step 4.</strong> Plan your moves carefully. For example, make a peanuts donation to the Logtalk hosting expenses. It&#8217;s one less burger and cola, which in itself is not a bad idea. Who knows? It might become handy in the future to claim that you had gone as far as contributing financially to the original project.
</p>
<p>
<strong>Step 5.</strong> Try to dictate the Logtalk roadmap in a public Logtalk wiki. Users write wish lists; developers write roadmaps. But who cares about these fine distinctions? The important bit is that you may now argue that your &#8220;collaboration&#8221; attempts got shut down by the ungrateful Logtalk developer.
</p>
<p>
<strong>Step 6.</strong> Fork Logtalk. Forks can be a fantastic tool for collaborative development. So much that Logtalk is available not only from an <a href="http://svn.logtalk.org/">open-access Subversion server</a> but also from a <a href="http://github.com/pmoura/logtalk">git repository</a> in a convenient public place. Of course, a fork starts as being an exact copy of the existing software.
</p>
<p>
<strong>Step 7.</strong> Take a page from Microsoft and name your fork <a href="http://wiki.github.com/ParkerJones/logtalk/">OpenLogtalk</a>. This will make it easier for new users to peek the most <a href="http://logtalk.org/license.html">open</a> alternative. Is dead simple: just choose the one with &#8220;open&#8221; in its name. Duh!
</p>
<p>
<strong>Step 8.</strong> Present your work as an upcoming professional alternative to the original academic and amateur one. Sprinkle the description of your fork with concepts from Software Engineering 101. Talk how you&#8217;re going to provide &#8220;high reliability&#8221; and &#8220;comprehensive documentation&#8221;. Talk is cheap; you can afford it.
</p>
<p>
<strong>Step 9.</strong> Present your work as a new implementation, while kindly acknowledging the first and original implementation. For example, <a href="http://github.com/ParkerJones/logtalk/commit/000ae7b011e25093f4daa206a129df46ff359fce">write</a>:
</p>
<blockquote>
<p>OpenLogtalk is an implementation of the &#8220;Logtalk language&#8221;.</p>
<p>The first implementation of Logtalk was by Paulo Moura.</p>
</blockquote>
<p>
The article &#8220;an&#8221; is a good choice as it nicely suggests &#8220;another&#8221; and &#8220;alternative&#8221;. Don&#8217;t let the little fact that the first implementation is also the only existing one, that you forked, spoil your message. Deception, after all, is an art that requires practice.
</p>
<p>
<strong>Step 10.</strong> Make cosmetic changes to your fork. <a href="http://github.com/ParkerJones/logtalk/commit/0d3490dda5bfad0b524bdce0999a42b3ecaa484f">Change tabs into spaces</a>, <a href="http://github.com/ParkerJones/logtalk/commit/a71d90753b0407a60ac8742270a5015cdd44df63">put a tab before comment text</a>, <a href="http://github.com/ParkerJones/logtalk/commit/21137e1102fada20c2b679fe352c1d3d49a3b71a">split files in smaller files</a> (nothing rhymes more with &#8220;modular&#8221; than a lot of small files, even if you just end up <a href="http://github.com/ParkerJones/logtalk/blob/modules1/compiler/load.pl">loading all of them</a>), <a href="http://github.com/ParkerJones/logtalk/commit/2d858195ac26e70a6b7c4e8b4a49dbe219ad0631">remove a prefix from internal names</a>, never mind that is there for sound technical reasons as <a href="http://forums.logtalk.org/viewtopic.php?f=13&amp;t=115">already explained to you</a>.
</p>
<p>
These changes are very important as they (1) make the code in your fork look different in a quick glance; (2) make the code fit your programming style (<a href="http://trac.logtalk.org/wiki/CodingGuidelines">coding guidelines</a> of the original developer be damned; it&#8217;s your fork!); (3) make it next to impossible for the original developer to pull and include your changes without lots of rewriting work; (4) reinforce the reality distortion field that you jump-started in the previous steps. As a bonus, you may get to claim later on the road the the original developer is not playing nice as he is not picking up your &#8220;contributions&#8221;.
</p>
<p>
<strong>Step 11.</strong> Innocently ask the original developer for help in understanding the source code. Put his mail replies in <a href="http://github.com/ParkerJones/logtalk/commit/231ea6405963a01f7e56bc6843eda998ce0c01e7">new files</a> in your fork. It helps in <a href="http://github.com/ParkerJones/logtalk/commit/8cbcb51b34baf9cbb56e4a64eeeb48c8699fb241">product differentiation</a>.
</p>
<p>
<strong>Step 12.</strong> There is no step 12. You&#8217;re already using a fork, not for collaborating, but to split. The best thing that can happen to a young programming community. Just let it roll.
</p>
<p>
<strong>P.S.</strong> If you care about Logtalk, help to spread this post and expose the troll.
</p>
<p>
Logtalk is the result of more than 12 years of hard work. Logtalk is, always have been, and always will be open for collaborations. Is not open, however, for abuse from disgruntled commercial users.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2010%2F06%2Fhow-to-misappropriate-and-misrepresent-other-peoples-hard-work-in-12-easy-steps%2F&amp;title=How%20To%20Misappropriate%20and%20Misrepresent%20Other%20People%26%238217%3Bs%20Hard%20Work%20in%2012%20Easy%20Steps" id="wpa2a_12">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2010/06/how-to-misappropriate-and-misrepresent-other-peoples-hard-work-in-12-easy-steps/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Logtalk source code history visualization movies</title>
		<link>http://blog.logtalk.org/2010/05/logtalk-source-code-history-visualization-movies/</link>
		<comments>http://blog.logtalk.org/2010/05/logtalk-source-code-history-visualization-movies/#comments</comments>
		<pubDate>Tue, 25 May 2010 00:05:12 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=534</guid>
		<description><![CDATA[Recently I come across two open-source tools for visualization of the commit history of source code ...]]></description>
			<content:encoded><![CDATA[<p>Recently I came across two open-source tools for visualization of the commit history of source code: <a href="http://code.google.com/p/codeswarm/">codeswarm</a> and <a href="http://code.google.com/p/gource/">gource</a>. Both tools support Subversion, the version control software currently used for Logtalk. Before that I used CVS. Unfortunately, the Logtalk Subversion repository only covers development from October 29, 2001 onwards (Logtalk 2.x development started on January, 1998). Even so, using the above tools provide interesting insight into the history of Logtalk for the past eight and a half years. The resulting videos are encoding using the MPEG-4 H264 video codec. I tried to upload the videos to YouTube but the apparently mandatory reconversion produced awful results.</p>
<p>The first video shows the Logtalk <em>code swarm</em> between October 29, 2001 and May 4, 2010 (the date of the latest Logtalk stable release, version 2.39.2):</p>
<p><a href="http://logtalk.org/files/logtalk_code_swarm.mp4">http://logtalk.org/files/logtalk_code_swarm.mp4</a></p>
<p>You will notice that the red color, representing commits related to the Prolog config files, often dominates. This is consequence of the lack of strong Prolog standards, which result in spending an inordinate amount of time working around portability issues.</p>
<p>The second video was produced by gource and covers the same time period:</p>
<p><a href="http://logtalk.org/files/logtalk_gource.mp4">http://logtalk.org/files/logtalk_gource.mp4</a></p>
<p>This video excels at illustrating all aspects of Logtalk development work other than the Logtalk compiler/runtime itself. The &#8220;flashes&#8221; where the little green guy seems to touch most files happen when a new Logtalk version is released and I increment the version number in order to begin working on the next release.</p>
<p>A special thanks to the developers of the codeswarm and gource tools.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2010/05/logtalk-source-code-history-visualization-movies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://logtalk.org/files/logtalk_gource.mp4" length="26353104" type="video/mp4" />
		</item>
		<item>
		<title>Spring cleaning coming</title>
		<link>http://blog.logtalk.org/2010/02/spring-cleaning-coming/</link>
		<comments>http://blog.logtalk.org/2010/02/spring-cleaning-coming/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 16:10:19 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[prolog]]></category>
		<category><![CDATA[portability]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=523</guid>
		<description><![CDATA[The development of the current generation of Logtalk, 2.x, began on January of 1998. At that time, the ISO Prolog Standard (Part 1: General Core) was only three years old. Thus, accepting and dealing with the lack of compliance of most Prolog compilers with the standard was a sensible choice. Back to the present. The [...]]]></description>
			<content:encoded><![CDATA[<p>The development of the current generation of Logtalk, 2.x, began on January of 1998. At that time, the ISO Prolog Standard (Part 1: General Core) was only three years old. Thus, accepting and dealing with the lack of compliance of most Prolog compilers with the standard was a sensible choice.</p>
<p>Back to the present. The ISO Prolog Standard is now 15 years old. Compliance with the standard greatly improved for some but not all Prolog compilers. Trying to keep minimal Logtalk compatibility with some of the existing Prolog compilers is no longer feasible. In fact, keeping compatibility with the most problematic Prolog compilers (as far as standard-compliance goes) is working as an anchor, slowing Logtalk development and preventing improvements and implementation of new features.</p>
<p>Some of the most problematic Prolog compilers (again, from the point-of-view of standards compliance) are (to the best of my knowledge) no longer being developed. Other Prolog compilers, actively maintained today, decided to ignore the current official and de facto standards. A few, such as IF/Prolog, provided good standard compliance but have been apparently discontinued by their developers.</p>
<p>I plan to ditch Logtalk compatibility with the following Prolog compilers in the upcoming 2.39.0 release: ALS Prolog, Amzi! Prolog, BinProlog, GNU Prolog, IF/Prolog, JIProlog, K-Prolog, LPA MacProlog, LPA WinProlog, Open Prolog, MasterProlog, PrologII+, Quintus Prolog. This may seem like a long list but I suspect this decision will have no consequence for most (if not all) Logtalk users. If If you think it is still worth to support some compiler in this list  please contact me as soon as possible.</p>
<p>UPDATE: added GNU Prolog to the list of no longer supported compilers. Support for this compiler will be restored as soon as it implements the ISO Prolog standard directive multifile/1.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.logtalk.org%2F2010%2F02%2Fspring-cleaning-coming%2F&amp;title=Spring%20cleaning%20coming" id="wpa2a_14">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2010/02/spring-cleaning-coming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lambda expressions in Logtalk</title>
		<link>http://blog.logtalk.org/2009/12/lambda-expressions-in-logtalk/</link>
		<comments>http://blog.logtalk.org/2009/12/lambda-expressions-in-logtalk/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 16:16:44 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[prolog]]></category>
		<category><![CDATA[lambdas]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=453</guid>
		<description><![CDATA[Logtalk 2.38.0, released earlier this month, adds support for <a href="http://en.wikipedia.org/wiki/Lambda_calculus">lambda expressions...]]></description>
			<content:encoded><![CDATA[<p>Logtalk 2.38.0, released earlier this month, adds support for <a href="http://en.wikipedia.org/wiki/Lambda_calculus">lambda expressions</a>. A simple example of a lambda expression is:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">| <span style="color: #666666;font-weight: bold;">?-</span> meta<span style="color: #666666;font-weight: bold;">::</span>map([<span style="color: #848484;">X</span>,<span style="color: #848484;">Y</span>]<span style="color: #666666;font-weight: bold;">&gt;&gt;</span>(<span style="color: #848484;">Y</span> <span style="color: #9d4f37;">is</span> <span style="color: #430000;">2</span><span style="color: #666666;font-weight: bold;">*</span><span style="color: #848484;">X</span>), [<span style="color: #430000;">1</span>,<span style="color: #430000;">2</span>,<span style="color: #430000;">3</span>], <span style="color: #848484;">Ys</span>).
<span style="color: #848484;">Ys</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #430000;">2</span>,<span style="color: #430000;">4</span>,<span style="color: #430000;">6</span>]
yes</pre></div></div>

</blockquote>
<p>In this example, a lambda expression, <code>[X,Y]&gt;&gt;(Y is 2*X)</code>, is used as an argument to the <code>map/3</code> list mapping predicate, defined in the library object <code>meta</code>, in order to double the elements of a list of integers. Using a lambda expression avoids writing an auxiliary predicate for the sole purpose of doubling the list elements. The lambda parameters are represented by the list <code>[X,Y]</code>, which is connected to the lambda goal, <code>(Y is 2*X)</code>, by the <code>(&gt;&gt;)/2</code> operator.</p>
<p>Currying is supported. I.e. it is possible to write a lambda expression whose goal is another lambda expression. The above example can be rewritten as:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">| <span style="color: #666666;font-weight: bold;">?-</span> meta<span style="color: #666666;font-weight: bold;">::</span>map([<span style="color: #848484;">X</span>]<span style="color: #666666;font-weight: bold;">&gt;&gt;</span>([<span style="color: #848484;">Y</span>]<span style="color: #666666;font-weight: bold;">&gt;&gt;</span>(<span style="color: #848484;">Y</span> <span style="color: #9d4f37;">is</span> <span style="color: #430000;">2</span><span style="color: #666666;font-weight: bold;">*</span><span style="color: #848484;">X</span>)), [<span style="color: #430000;">1</span>,<span style="color: #430000;">2</span>,<span style="color: #430000;">3</span>], <span style="color: #848484;">Ys</span>).
<span style="color: #848484;">Ys</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #430000;">2</span>,<span style="color: #430000;">4</span>,<span style="color: #430000;">6</span>]
yes</pre></div></div>

</blockquote>
<p>Lambda expressions may also contain lambda free variables. I.e. variables that are global to the lambda expression. For example, using GNU Prolog as the back-end compiler, we can write:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">| <span style="color: #666666;font-weight: bold;">?-</span> meta<span style="color: #666666;font-weight: bold;">::</span>map(<span style="color: #666666;font-weight: bold;">{</span><span style="color: #848484;">Z</span><span style="color: #666666;font-weight: bold;">}</span><span style="color: #666666;font-weight: bold;">/</span>[<span style="color: #848484;">X</span>,<span style="color: #848484;">Y</span>]<span style="color: #666666;font-weight: bold;">&gt;&gt;</span>(<span style="color: #848484;">Z</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">X</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">Y</span>), [<span style="color: #430000;">1</span>,<span style="color: #430000;">2</span>,<span style="color: #430000;">3</span>], <span style="color: #848484;">Zs</span>).
<span style="color: #848484;">Z</span> <span style="color: #666666;font-weight: bold;">=</span> <span style="color: #848484;">_</span>#<span style="color: #430000;">22</span>(<span style="color: #430000;">3</span>..<span style="color: #430000;">268435455</span>)
<span style="color: #848484;">Zs</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_</span>#<span style="color: #430000;">3</span>(<span style="color: #430000;">2</span>..<span style="color: #430000;">268435454</span>),<span style="color: #848484;">_</span>#<span style="color: #430000;">66</span>(<span style="color: #430000;">1</span>..<span style="color: #430000;">268435453</span>),<span style="color: #848484;">_</span>#<span style="color: #430000;">110</span>(<span style="color: #430000;">0</span>..<span style="color: #430000;">268435452</span>)]
yes</pre></div></div>

</blockquote>
<p>Logtalk uses the ISO Prolog construct <code>{}/1</code> for representing the lambda free variables as this representation is often associated with set representation. Note that the order of the free variables is of no consequence (on the other hand, a list is used for the lambda parameters as their order does matter).</p>
<p>Both lambda free variables and lambda parameters can be any Prolog term. Consider the following example by Markus Triska:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">| <span style="color: #666666;font-weight: bold;">?-</span> meta<span style="color: #666666;font-weight: bold;">::</span>map([<span style="color: #848484;">A</span><span style="color: #666666;font-weight: bold;">-</span><span style="color: #848484;">B</span>,<span style="color: #848484;">B</span><span style="color: #666666;font-weight: bold;">-</span><span style="color: #848484;">A</span>]<span style="color: #666666;font-weight: bold;">&gt;&gt;</span><span style="color: #9d4f37;">true</span>, [<span style="color: #430000;">1</span><span style="color: #666666;font-weight: bold;">-</span>a,<span style="color: #430000;">2</span><span style="color: #666666;font-weight: bold;">-</span>b,<span style="color: #430000;">3</span><span style="color: #666666;font-weight: bold;">-</span>c], <span style="color: #848484;">Zs</span>).
<span style="color: #848484;">Zs</span> <span style="color: #666666;font-weight: bold;">=</span> [a<span style="color: #666666;font-weight: bold;">-</span><span style="color: #430000;">1</span>,b<span style="color: #666666;font-weight: bold;">-</span><span style="color: #430000;">2</span>,c<span style="color: #666666;font-weight: bold;">-</span><span style="color: #430000;">3</span>]
yes</pre></div></div>

</blockquote>
<p>Lambda expressions can be used, as expected, in non-deterministic queries as in the following example using SWI-Prolog as the back-end compiler and Markus Triska&#8217;s CLP(FD) library:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">| <span style="color: #666666;font-weight: bold;">?-</span> meta<span style="color: #666666;font-weight: bold;">::</span>map(<span style="color: #666666;font-weight: bold;">{</span><span style="color: #848484;">Z</span><span style="color: #666666;font-weight: bold;">}</span><span style="color: #666666;font-weight: bold;">/</span>[<span style="color: #848484;">X</span>,<span style="color: #848484;">Y</span>]<span style="color: #666666;font-weight: bold;">&gt;&gt;</span>(clpfd<span style="color: #666666;font-weight: bold;">:</span>(<span style="color: #848484;">Z</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">X</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">Y</span>)), <span style="color: #848484;">Xs</span>, <span style="color: #848484;">Ys</span>).
<span style="color: #848484;">Xs</span> <span style="color: #666666;font-weight: bold;">=</span> [],
<span style="color: #848484;">Ys</span> <span style="color: #666666;font-weight: bold;">=</span> [] <span style="color: #666666;font-weight: bold;">;</span>
<span style="color: #848484;">Xs</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_G1369</span>],
<span style="color: #848484;">Ys</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_G1378</span>],
<span style="color: #848484;">_G1369</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">_G1378</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">Z</span> <span style="color: #666666;font-weight: bold;">;</span>
<span style="color: #848484;">Xs</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_G1579</span>, <span style="color: #848484;">_G1582</span>],
<span style="color: #848484;">Ys</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_G1591</span>, <span style="color: #848484;">_G1594</span>],
<span style="color: #848484;">_G1582</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">_G1594</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">Z</span>,
<span style="color: #848484;">_G1579</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">_G1591</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">Z</span> <span style="color: #666666;font-weight: bold;">;</span>
<span style="color: #848484;">Xs</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_G1789</span>, <span style="color: #848484;">_G1792</span>, <span style="color: #848484;">_G1795</span>],
<span style="color: #848484;">Ys</span> <span style="color: #666666;font-weight: bold;">=</span> [<span style="color: #848484;">_G1804</span>, <span style="color: #848484;">_G1807</span>, <span style="color: #848484;">_G1810</span>],
<span style="color: #848484;">_G1795</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">_G1810</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">Z</span>,
<span style="color: #848484;">_G1792</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">_G1807</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">Z</span>,
<span style="color: #848484;">_G1789</span><span style="color: #666666;font-weight: bold;">+</span><span style="color: #848484;">_G1804</span>#<span style="color: #666666;font-weight: bold;">=</span><span style="color: #848484;">Z</span> <span style="color: #666666;font-weight: bold;">;</span>
...</pre></div></div>

</blockquote>
<p>As illustrated by the above examples, Logtalk lambda expression syntax reuses the ISO Prolog construct <code>{}/1</code> and the standard operators <code>(/)/2</code> and <code>(&gt;&gt;)/2</code>, thus avoiding defining new operators, which is always tricky for a portable system such as Logtalk. The operator <code>(&gt;&gt;)/2</code> was chosen as it suggests an arrow, similar to the syntax used in other languages such as OCaml and Haskell to connect lambda parameters with lambda functions. This syntax was also chosen in order to simplify parsing, error checking, and, eventually, compilation of lambda expressions. The specification of the Logtalk lambda expression syntax can be found in the Logtalk <a href="http://logtalk.org/manuals/refman/grammar.html#grammar_lambdas">reference manual</a>. The current Logtalk version also includes an example, <a href="http://svn.logtalk.org/viewvc.cgi/trunk/examples/lambdas/"><code>lambdas</code></a>, of using lambda expressions with a <a href="http://svn.logtalk.org/viewvc.cgi/trunk/examples/lambdas/SCRIPT.txt">fair number of sample queries</a>.</p>
<p>Although the first, experimental implementation of lambda expressions in Logtalk followed Ulrich Neumerkel&#8217;s <a href="http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord.html">proposal</a> for lambda expression syntax in Prolog, that representation was dropped and replaced by the current one in order to avoid some of the questions raised by the Ulrich&#8217;s proposed syntax. In his proposal, lambda expressions start with the <code>()/1</code> prefix operator, which can be seen as an approximation to the greek letter lambda (λ). However, the backslash character is usually associated in Prolog with negation as found e.g. in the standard operators <code>(+)/1</code>, <code>(==)/2</code>, <code>(=)/2</code>, and <code>(==)/2</code>. Another issue with this operator is that users must be careful when the first lambda parameter is enclosed in parentheses. Consider the  following example by Markus (using SWI-Prolog with Ulrich&#8217;s <code>lambda</code> library):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;">| <span style="color: #666666;font-weight: bold;">?-</span> maplist((<span style="color: #848484;">A</span><span style="color: #666666;font-weight: bold;">-</span><span style="color: #848484;">B</span>)^(<span style="color: #848484;">B</span><span style="color: #666666;font-weight: bold;">-</span><span style="color: #848484;">A</span>)^true, [<span style="color: #430000;">1</span><span style="color: #666666;font-weight: bold;">-</span>a,<span style="color: #430000;">2</span><span style="color: #666666;font-weight: bold;">-</span>b,<span style="color: #430000;">3</span><span style="color: #666666;font-weight: bold;">-</span>c], <span style="color: #848484;">Zs</span>).
false.</pre></div></div>

</blockquote>
<p>The goal fails because there is a missing space between the <code>()/1</code> prefix operator and the opening parenthesis that follows. A likely trap for beginners. Ulrich&#8217;s syntax for lambda free variables requires adding a new infix operator, <code>(+)/1</code>, to the base language, something that I prefer to avoid. Not to mention that this operator is too similar to the Prolog negation operator, <code>(+)/1</code>. Parsing lambda parameters also needs to be careful to avoid calling a non-existing <code>(^)/2</code> predicate when the lambda expression is misformed. Parsing lambda parameters is arguably simpler in Logtalk due to the use of a list plus using the <code>(&gt;&gt;)/2</code> operator to connect the parameters with the lambda goal.</p>
<p>The Logtalk implementation of lambda expressions is still evolving. The current development version features improved error-checking and adds support for using a <code>(&gt;&gt;)/2</code> lambda expression as a goal (besides as a meta-predicate closure). No optimizations are yet in-place. Thus, be aware of possible performance issues if you plan to use lambda expressions heavily in your applications. But don&#8217;t let that stop you from having fun playing with Lambda expressions in Logtalk. As always, your feedback is appreciated. Thanks to Ulrich Neumerkel, Richard O&#8217;Keefe, and Markus Triska for their lambda expression examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2009/12/lambda-expressions-in-logtalk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with data sets</title>
		<link>http://blog.logtalk.org/2009/10/working-with-data-sets/</link>
		<comments>http://blog.logtalk.org/2009/10/working-with-data-sets/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 18:27:48 +0000</pubDate>
		<dc:creator>Paulo Moura</dc:creator>
				<category><![CDATA[logtalk]]></category>
		<category><![CDATA[prolog]]></category>

		<guid isPermaLink="false">http://blog.logtalk.org/?p=416</guid>
		<description><![CDATA[A recurring question on the comp.lang.prolog newsgroup is how to work with different data sets, loading them from different files, without mixing the data in the plain Prolog database ...]]></description>
			<content:encoded><![CDATA[<p>A recurring question on the <a href="http://groups.google.com/group/comp.lang.prolog/topics">comp.lang.prolog</a> newsgroup is how to work with different data sets, usually loading them from different files, without mixing the data in the plain Prolog database. Unfortunately, these questions often lack enough details for making an informed choice between several potential programming solutions. Two possible solutions are (1) load the data into suitable data structures instead of using the database and (2) use clauses to represent the data but encapsulate each data set in its own Prolog module or Logtalk object. Some combination of both solutions may also be possible. In this post, however, we&#8217;re going to sketch the second solution using Logtalk objects. For an alternative but also Logtalk-based solution please see <a href="http://blog.logtalk.org/2009/02/15/efficient-representation-of-data-objects/">this</a> previous post.</p>
<p>Assuming all data sets are described using the same predicates, the first step is to declare these predicates. The predicate declarations can be encapsulated either in an object or in a protocol (interface). Using a protocol we could write:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;"><span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">protocol</span>(data_set).
&nbsp;
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(datum_1<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">3</span>).  <span style="color: #60a0b0; font-style: italic;">% data set description predicates</span>
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(datum_2<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">5</span>).
    ...
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">end_protocol</span>.</pre></div></div>

</blockquote>
<p>We can now represent each data set using its own object (possibly stored in its own file). Each data set object implements the <code>data_set</code> protocol defined above. For example:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;"><span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">object</span>(data_set_1,
    <span style="color: #2e4dc9;">implements</span>(data_set)).
&nbsp;
    datum_1(a, b, c).
    ...
&nbsp;
    datum_2(<span style="color: #430000;">1</span>, <span style="color: #430000;">2</span>, <span style="color: #430000;">3</span>, <span style="color: #430000;">4</span>, <span style="color: #430000;">5</span>).
    ...
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">end_object</span>.</pre></div></div>

</blockquote>
<p>Assuming we have the required memory, we can load some of all of our data sets without mixing their data. But that&#8217;s not all. We can also encapsulated our data set processing code in its own object (or set of objects, or hierarchy of objects, or whatever is suitable to the complexity of our application). This object, let&#8217;s name it <code>processor</code>, will perform its magic by sending messages to the specific data set that we want to process. For example:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;"><span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">object</span>(processor).
&nbsp;
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(compute<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">2</span>).
    ...
&nbsp;
    compute(<span style="color: #848484;">DataSet</span>, <span style="color: #848484;">Computation</span>) <span style="color: #000000;">:-</span>
        <span style="color: #848484;">DataSet</span><span style="color: #666666;font-weight: bold;">::</span>datum_1(<span style="color: #848484;">A</span>, <span style="color: #848484;">B</span>, <span style="color: #848484;">C</span>),
        ...
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">end_object</span>.</pre></div></div>

</blockquote>
<p>If the computations we wish to perform make sense as questions sent to the data sets themselves, an alternative is to move the data set predicate declarations from the <code>data_set</code> protocol to the <code>processor</code> object and make the data set objects extend the resulting object, below renamed as <code>data_set</code>. For example:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="logtalk" style="font-family:monospace;"><span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">object</span>(data_set).
&nbsp;
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(datum_1<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">3</span>).  <span style="color: #60a0b0; font-style: italic;">% data set description predicates</span>
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(datum_2<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">5</span>).
    ...
    <span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">public</span>(compute<span style="color: #666666;font-weight: bold;">/</span><span style="color: #430000;">1</span>).  <span style="color: #60a0b0; font-style: italic;">% computing predicates</span>
    ...
&nbsp;
    datum_3(abc, def).     <span style="color: #60a0b0; font-style: italic;">% default value for datum_3/2</span>
&nbsp;
    compute(<span style="color: #848484;">Computation</span>) <span style="color: #000000;">:-</span>
        <span style="color: #666666;font-weight: bold;">::</span>datum_1(<span style="color: #848484;">A</span>, <span style="color: #848484;">B</span>, <span style="color: #848484;">C</span>),
        ...
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">end_object</span>.
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">object</span>(data_set_1,
    <span style="color: #2e4dc9;">extends</span>(data_set)).
&nbsp;
    datum_1(a, b, c).
    ...
&nbsp;
    datum_2(<span style="color: #430000;">1</span>, <span style="color: #430000;">2</span>, <span style="color: #430000;">3</span>, <span style="color: #430000;">4</span>, <span style="color: #430000;">5</span>).
    ...
&nbsp;
<span style="color: #000000;">:-</span> <span style="color: #2e4dc9;">end_object</span>.</pre></div></div>

</blockquote>
<p>An advantage of this solution is that the object <code>data_set</code> can contain default values for the data set description predicates. The <code>::/1</code> operator used above is the Logtalk operator for sending a message to <em>self</em>, i.e. to the data set object that received the message <code>compute/1</code>. If the information requested is not found in the data set object, then it will be looked for in its ancestor, where the default values are defined.</p>
<p>The best and most elegant solution will, of course, depend on the details on the data set processing application. For example, above we could have defined the object <code>data_set</code> as a class and the individual data sets as instances of this class (technically, the solution above uses prototypes).</p>
<p>Note that all code above is static. Individual data set description predicates may be declared dynamic (using the predicate directive <code>dynamic/1</code>) if we need to update them during processing of the data sets. If our application requires being able to delete data sets from memory, is simply a question of declaring the data set objects dynamic using the Logtalk object directive <code>dynamic/0</code> and to use the Logtalk built-in predicate <code>abolish_object/1</code> when a data set object is no longer needed. </p>
<p>We have only scratched the surface of the Logtalk features that we could make use in our implementation but, hopefully, it&#8217;s enough as a starting guide. Feel free to stop by the <a href="http://forums.logtalk.org">Logtalk discussion forums</a> to further discuss this programming pattern.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.logtalk.org/2009/10/working-with-data-sets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

