<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.visual-prolog.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Adam+Rose</id>
	<title>wiki.visual-prolog.com - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.visual-prolog.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Adam+Rose"/>
	<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Special:Contributions/Adam_Rose"/>
	<updated>2026-04-11T23:58:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Succeed,_fail_and_backtrack_-_part_3&amp;diff=4967</id>
		<title>Lessons/Succeed, fail and backtrack - part 3</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Succeed,_fail_and_backtrack_-_part_3&amp;diff=4967"/>
		<updated>2024-10-11T09:31:55Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here we will consider more ways to use the knowledge in our little &amp;quot;knowledge base&amp;quot; (i.e. from {{lesson|Succeed, fail and backtrack - part 2}}).&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the runGoal clauses like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        father(Person, Father),&lt;br /&gt;
        stdio::writef(&amp;quot;% is the father of %.\n&amp;quot;, Father, Person).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And run the program.}}&lt;br /&gt;
&lt;br /&gt;
This clause will call &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; with two free variables, i.e. both arguments are output arguments.  Therefore it will succeed for the first clause and have created a backtrack point to the second clause.  And so forth.&lt;br /&gt;
&lt;br /&gt;
Notice that the actual backtracking takes place from &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; to &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Try this instead:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        foreach father(Person, Father) do&lt;br /&gt;
            stdio::writef(&amp;quot;% is the father of %.\n&amp;quot;, Father, Person)&lt;br /&gt;
        end foreach,&lt;br /&gt;
        stdio::write(&amp;quot;That is all we know about fathers\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;foreach &amp;lt;P&amp;gt; do &amp;lt;Q&amp;gt; end foreach&amp;lt;/vp&amp;gt; is a construction that executes &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; and if it succeeds then it executes &amp;lt;vp&amp;gt;&amp;lt;Q&amp;gt;&amp;lt;/vp&amp;gt; after &amp;lt;vp&amp;gt;&amp;lt;Q&amp;gt;&amp;lt;/vp&amp;gt; has executed it will backtrack into &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; if that is possible and if &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; succeeds again then &amp;lt;vp&amp;gt;&amp;lt;Q&amp;gt;&amp;lt;/vp&amp;gt; is also run again, this continues until &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; finally fails, at which point the execution will continue after &amp;lt;vp&amp;gt;end foreach&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt; is a built-in predicate that always fails, it can be used to achieve a similar behavior as the one &amp;lt;vp&amp;gt;foreach&amp;lt;/vp&amp;gt; achieves:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Try this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        father(Person, Father),&lt;br /&gt;
        stdio::writef(&amp;quot;% is the father of %.\n&amp;quot;, Father, Person),&lt;br /&gt;
        fail.&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        stdio::write(&amp;quot;That is all we know about fathers\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
After we have found a &amp;lt;vp&amp;gt;Person&amp;lt;/vp&amp;gt; and its &amp;lt;vp&amp;gt;Father&amp;lt;/vp&amp;gt; and written it we call &amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt;.  And since &amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt; fails we will backtrack:&lt;br /&gt;
&lt;br /&gt;
* Into &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; if there is a backtrack point there.&lt;br /&gt;
* And otherwise to the second &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
So besides the syntactic difference in using &amp;lt;vp&amp;gt;foreach&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt; there is also the difference that after having found all fathers, the &amp;lt;vp&amp;gt;foreach&amp;lt;/vp&amp;gt; construction will &amp;#039;&amp;#039;&amp;#039;succeed&amp;#039;&amp;#039;&amp;#039; and execution will therefore continue after &amp;lt;vp&amp;gt;end foreach&amp;lt;/vp&amp;gt; in the &amp;#039;&amp;#039;&amp;#039;same&amp;#039;&amp;#039;&amp;#039; clause; &amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt; on the other hand fails, so in after having found all fathers fail will fail, and we will therefore the entire clause containing &amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt; will itself fail, and execution will therefore continue in the &amp;#039;&amp;#039;&amp;#039;next&amp;#039;&amp;#039;&amp;#039; clause.&lt;br /&gt;
&lt;br /&gt;
Summary:&lt;br /&gt;
&lt;br /&gt;
* We can use the &amp;quot;knowledge base&amp;quot; with different combinations of bound and free arguments.&lt;br /&gt;
* &amp;lt;vp&amp;gt;foreach&amp;lt;/vp&amp;gt; can be used to exhaust backtracking of a certain &amp;quot;generator&amp;quot; and perform some action of each &amp;quot;generated thing&amp;quot;.&lt;br /&gt;
* when the backtracking in a &amp;lt;vp&amp;gt;foreach&amp;lt;/vp&amp;gt; construction is finally exhausted, the entire &amp;lt;vp&amp;gt;foreach&amp;lt;/vp&amp;gt; construction succeeds.&lt;br /&gt;
* &amp;lt;vp&amp;gt;fail&amp;lt;/vp&amp;gt; is a built-in predicate that fails when called.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Try this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        Person = &amp;quot;Sue&amp;quot;,&lt;br /&gt;
        if father(Person, Father) then&lt;br /&gt;
            stdio::writef(&amp;quot;% is the father of %.\n&amp;quot;, Father, Person)&lt;br /&gt;
        else&lt;br /&gt;
            stdio::writef(&amp;quot;We don&amp;#039;t kno who the father of % is.\n&amp;quot;, Person)&lt;br /&gt;
        end if,&lt;br /&gt;
        stdio::write(&amp;quot;&amp;lt;&amp;lt;end&amp;gt;&amp;gt;\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
Also try it with &amp;lt;vp&amp;gt;Person = &amp;quot;Pam&amp;quot;&amp;lt;/vp&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;if &amp;lt;C&amp;gt; then &amp;lt;P&amp;gt; else &amp;lt;Q&amp;gt; end if&amp;lt;/vp&amp;gt; is a construction that will first execute &amp;lt;vp&amp;gt;&amp;lt;C&amp;gt;&amp;lt;/vp&amp;gt; if that succeeds it will execute &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; if it fails it will execute &amp;lt;vp&amp;gt;&amp;lt;Q&amp;gt;&amp;lt;/vp&amp;gt; instead. Backtrack points in &amp;lt;vp&amp;gt;&amp;lt;C&amp;gt;&amp;lt;/vp&amp;gt; (if any) will be discarded, so there will be no backtracking into &amp;lt;vp&amp;gt;&amp;lt;C&amp;gt;&amp;lt;/vp&amp;gt;. So &amp;lt;vp&amp;gt;&amp;lt;C&amp;gt;&amp;lt;/vp&amp;gt; is used to choose between &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;&amp;lt;Q&amp;gt;&amp;lt;/vp&amp;gt;.  If (let us say) &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; is chosen then the entire &amp;lt;vp&amp;gt;if&amp;lt;/vp&amp;gt; construction functions as if &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; was called.  So if &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; fails then the entire &amp;lt;vp&amp;gt;if&amp;lt;/vp&amp;gt; construction fails, and it &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; succeeds then the entire &amp;lt;vp&amp;gt;if&amp;lt;/vp&amp;gt; construction succeeds.  Finally, if &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; created backtrack points then backtracking will return into &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t want anything to happen in the then-part you can use the built-in &amp;lt;vp&amp;gt;succeed&amp;lt;/vp&amp;gt; predicate, which simply succeeds, or you can write nothing at all: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
if &amp;lt;C&amp;gt; then succeed else &amp;lt;Q&amp;gt; end if&lt;br /&gt;
if &amp;lt;C&amp;gt; then else &amp;lt;Q&amp;gt; end if&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t want anything to take place in the &amp;lt;vp&amp;gt;else&amp;lt;/vp&amp;gt; part you can also leave out the word &amp;lt;vp&amp;gt;else&amp;lt;/vp&amp;gt;, so these three things have the same meaning:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
if &amp;lt;C&amp;gt; then &amp;lt;P&amp;gt; else succeed end if&lt;br /&gt;
if &amp;lt;C&amp;gt; then &amp;lt;P&amp;gt; else end if&lt;br /&gt;
if &amp;lt;C&amp;gt; then &amp;lt;P&amp;gt; end if&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Summary&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;vp&amp;gt;succeed&amp;lt;/vp&amp;gt; is a build-in predicate that succeeds&lt;br /&gt;
* &amp;lt;vp&amp;gt;if &amp;lt;C&amp;gt; then &amp;lt;P&amp;gt; else &amp;lt;Q&amp;gt; end if&amp;lt;/vp&amp;gt; runs &amp;lt;vp&amp;gt;C&amp;lt;/vp&amp;gt; to choose between &amp;lt;vp&amp;gt;&amp;lt;P&amp;gt;&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;&amp;lt;Q&amp;gt;&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Succeed,_fail_and_backtrack_-_part_2&amp;diff=4966</id>
		<title>Lessons/Succeed, fail and backtrack - part 2</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Succeed,_fail_and_backtrack_-_part_2&amp;diff=4966"/>
		<updated>2024-10-11T09:14:26Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: spelling and grammar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In {{Lesson|Succeed, fail and backtrack - part 1}} we described what it means that a predicate succeeds and fails and what backtracking means.  By examining a very small program with an extremely little &amp;quot;knowledge base&amp;quot;.  Here we&amp;#039;ll discuss how we can add more abstract rules to such a knowledge base.&lt;br /&gt;
&lt;br /&gt;
In particular we will look at the mentioned grandfather rule:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;C is the grandfather of A if C is the father of B and B is the father of A&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rule as it is written here is actually more or less a Visual Prolog clause:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|And an extra &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
	father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;).&lt;br /&gt;
	father(&amp;quot;Pam&amp;quot;, &amp;quot;Bill&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And add a &amp;lt;vp&amp;gt;grandfather&amp;lt;/vp&amp;gt; predicate:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
class predicates&lt;br /&gt;
    grandfather : (string Person, string Grandfather) nondeterm anyflow.&lt;br /&gt;
clauses&lt;br /&gt;
    grandfather(Person, Grandfather) :-&lt;br /&gt;
        father(Father, Grandfather),&lt;br /&gt;
        father(Person, Father).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project.}}&lt;br /&gt;
&lt;br /&gt;
In consistence wih my &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate, it is the second argument of the &amp;lt;vp&amp;gt;grandfather&amp;lt;/vp&amp;gt; predicate that is the grandfather.  In the clause I have chosen to use &amp;lt;vp&amp;gt;Person&amp;lt;/vp&amp;gt;, &amp;lt;vp&amp;gt;Father&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;Grandfather&amp;lt;/vp&amp;gt; as variable names instead of &amp;lt;vp&amp;gt;A&amp;lt;/vp&amp;gt;, &amp;lt;vp&amp;gt;B&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;C&amp;lt;/vp&amp;gt;, but otherwise the rule is a &amp;quot;direct&amp;quot; translation of the textual version.&lt;br /&gt;
&lt;br /&gt;
Let us test the new predicate in a way similar to how we tested the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clauses like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        grandfather(&amp;quot;Pam&amp;quot;, &amp;quot;John&amp;quot;),&lt;br /&gt;
        stdio::write(&amp;quot;Yes, John is the grandfather of Pam\n&amp;quot;).&lt;br /&gt;
    runGoal() :-&lt;br /&gt;
        not(grandfather(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;)),&lt;br /&gt;
        stdio::write(&amp;quot;No, John is not the grandfather of Bill\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the project.}}&lt;br /&gt;
&lt;br /&gt;
When &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; calls &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; we first create a backtrack point to the second &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause and then execute the first clause.&lt;br /&gt;
&lt;br /&gt;
In the first &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause we call &amp;lt;vp&amp;gt;grandfather(&amp;quot;Pam&amp;quot;, &amp;quot;John&amp;quot;)&amp;lt;/vp&amp;gt;, so when we enter the &amp;lt;vp&amp;gt;grandfather&amp;lt;/vp&amp;gt; clause &amp;lt;vp&amp;gt;Person&amp;lt;/vp&amp;gt; is &amp;lt;vp&amp;gt;&amp;quot;Pam&amp;quot;&amp;lt;/vp&amp;gt; and Grandfather is &amp;lt;vp&amp;gt;&amp;quot;John&amp;quot;&amp;lt;/vp&amp;gt;.  We will say that &amp;lt;vp&amp;gt;Person&amp;lt;/vp&amp;gt; is &amp;#039;&amp;#039;&amp;#039;bound&amp;#039;&amp;#039;&amp;#039; to &amp;lt;vp&amp;gt;&amp;quot;Pam&amp;quot;&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;Grandfather&amp;lt;/vp&amp;gt; is &amp;#039;&amp;#039;&amp;#039;bound&amp;#039;&amp;#039;&amp;#039; to &amp;lt;vp&amp;gt;&amp;quot;John&amp;quot;&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;Father&amp;lt;/vp&amp;gt; is unbound or &amp;#039;&amp;#039;&amp;#039;free&amp;#039;&amp;#039;&amp;#039;.  If we substitute known values for the variables the clause looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
grandfather(&amp;quot;Pam&amp;quot;, &amp;quot;John&amp;quot;) :- father(Father, &amp;quot;John&amp;quot;), father(&amp;quot;Pam&amp;quot;, Father).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this clause we will first call the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate with a  &amp;#039;&amp;#039;&amp;#039;free&amp;#039;&amp;#039;&amp;#039; first argument and a &amp;#039;&amp;#039;&amp;#039;bound&amp;#039;&amp;#039;&amp;#039; second argument.  So the data flow in that call is that the first argument is an &amp;#039;&amp;#039;&amp;#039;output&amp;#039;&amp;#039;&amp;#039; argument and the second argument is an &amp;#039;&amp;#039;&amp;#039;input&amp;#039;&amp;#039;&amp;#039; argument.&lt;br /&gt;
&lt;br /&gt;
When we enter the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate we have two clauses, so the first thing that happens is that we create a backtrack point to the second clause and then execute the first clause.  Since our first argument is free it can match &amp;quot;Bill&amp;quot; in the clause, i.e. if we bind it to &amp;lt;vp&amp;gt;&amp;quot;Bill&amp;quot;&amp;lt;/vp&amp;gt;.  The second argument is &amp;quot;John&amp;quot; and that also matches &amp;quot;John&amp;quot; clause.  So the first clause succeeds and we return to the &amp;lt;vp&amp;gt;grandfather&amp;lt;/vp&amp;gt; clause where the &amp;lt;vp&amp;gt;Father&amp;lt;/vp&amp;gt; variable is now bound to &amp;lt;vp&amp;gt;&amp;quot;Bill&amp;quot;&amp;lt;/vp&amp;gt;.  If we substitute &amp;lt;vp&amp;gt;&amp;quot;Bill&amp;quot;&amp;lt;/vp&amp;gt; for the &amp;lt;vp&amp;gt;Father&amp;lt;/vp&amp;gt; variable the clause now looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
grandfather(&amp;quot;Pam&amp;quot;, &amp;quot;John&amp;quot;) :- father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;), father(&amp;quot;Pam&amp;quot;, &amp;quot;Bill&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So now we have to call &amp;lt;vp&amp;gt;father(&amp;quot;Pam&amp;quot;, &amp;quot;Bill&amp;quot;)&amp;lt;/vp&amp;gt;, which means that this time we call the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate with two &amp;#039;&amp;#039;&amp;#039;input&amp;#039;&amp;#039;&amp;#039; arguments.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate we again first create a backtrack point to the second clause, and then execute the first clause.  The first clause fails because the first argument in our call is &amp;lt;vp&amp;gt;&amp;quot;Pam&amp;quot;&amp;lt;/vp&amp;gt; but the first argument in the clause is &amp;lt;vp&amp;gt;&amp;quot;Bill&amp;quot;&amp;lt;/vp&amp;gt;.  There is no need to consider the second arguments, we just immediately invoke the backtracking mechanism which will bring us to the second clause.  The second clause succeeds and we return to the &amp;lt;vp&amp;gt;grandfather&amp;lt;/vp&amp;gt; predicate and since this was the last call in that clause the grandfather predicate also succeeds. &lt;br /&gt;
&lt;br /&gt;
So we return to &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; where we will write &amp;lt;vp&amp;gt;&amp;quot;Yes, John is the grandfather of Pam\n&amp;quot;&amp;lt;/vp&amp;gt;.  And then the first clause of &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; succeeds and we will return to the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Recall that the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate will make sure that all backtracking takes place, so carefully consider what happens next.  Do we have any backtrack points?  If so where do we backtrack to?}}&lt;br /&gt;
&lt;br /&gt;
Well if you considered correctly, you would recall that we have created three backtrack points in total and also used one of them, so we have two backtrack points left.&lt;br /&gt;
&lt;br /&gt;
The first we created was to the second clause in &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt;, the second backtrack point we created was to the second clause of the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate which we had called from the first call in the &amp;lt;vp&amp;gt;grandfather&amp;lt;/vp&amp;gt; predicate which we had called in the first clause in the &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; predicate.  Both these backtrack points still exists, and the one we created in the father predicate was the last one we created so this it the one we will backtrack to.&lt;br /&gt;
&lt;br /&gt;
So at this point we will backtrack to place that is nested rather deeply in something that we have already returned from once.  &lt;br /&gt;
&lt;br /&gt;
Furthermore at that backtrack point in the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate the first argument was free, when we executed the first clause in that predicate the variable became bound, but when we backtrack to this place the variable is again free.  So backtracking not only transfers the program control back to an earlier state, it also restores variables to the free/bound state they were in at that point. Notice that such restore of variables can only make variables free again, bound variables never receive new values, so bound variables already have the correct state.&lt;br /&gt;
&lt;br /&gt;
So we are back at the second clause &amp;lt;vp&amp;gt;father(&amp;quot;Pam&amp;quot;, &amp;quot;Bill&amp;quot;).&amp;lt;/vp&amp;gt; of the &amp;lt;vp&amp;gt;father&amp;lt;/vp&amp;gt; predicate with the first argument being free and the second argument being &amp;lt;vp&amp;gt;&amp;quot;John&amp;quot;&amp;lt;/vp&amp;gt;.  When we execute this clause we can bind the free first argument, but the &amp;lt;vp&amp;gt;&amp;quot;John&amp;quot;&amp;lt;/vp&amp;gt; does not match &amp;lt;vp&amp;gt;&amp;quot;Bill&amp;quot;&amp;lt;/vp&amp;gt;, so this clause fails.&lt;br /&gt;
&lt;br /&gt;
Once more we backtrack this time to the second clause of &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
So backtracking can jump quite a lot around in your program.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Succeed,_fail_and_backtrack_-_part_1&amp;diff=4965</id>
		<title>Lessons/Succeed, fail and backtrack - part 1</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Succeed,_fail_and_backtrack_-_part_1&amp;diff=4965"/>
		<updated>2024-10-11T07:44:53Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: small spelling mistakes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;So why is it a logical programming language? And why do we call it predicates and clauses?&lt;br /&gt;
&lt;br /&gt;
Logic is a formalized approach to&lt;br /&gt;
&lt;br /&gt;
* propositions like &amp;quot;John is the father of Bill&amp;quot;&lt;br /&gt;
* rules like &amp;quot;C is the grandfather of A if C is the father of B and B is the father of A&amp;quot;&lt;br /&gt;
* questions like &amp;quot;Who is the father of John&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Visual Prolog can formalize logical entities.  The Visual Prolog compiler has a number of strict validation checks that will help you write the programs you intend.  But to keep things simple we will &amp;quot;work around&amp;quot; those checks in this lesson.  To do that work around you should update enter the following code in the console project:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|In a console project update the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clause and add a &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; predicate, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        foreach runGoal() do&lt;br /&gt;
        end foreach.&lt;br /&gt;
&lt;br /&gt;
class predicates&lt;br /&gt;
    runGoal : () nondeterm.&lt;br /&gt;
clauses&lt;br /&gt;
    runGoal().&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project.}}&lt;br /&gt;
&lt;br /&gt;
Compared to what we have see so far you will notice the token &amp;lt;vp&amp;gt;nondeterm&amp;lt;/vp&amp;gt; in the declaration of &amp;lt;vp&amp;gt;run2&amp;lt;/vp&amp;gt; and you will also get a warning about &amp;#039;&amp;lt;vp&amp;gt;nondeterm&amp;lt;/vp&amp;gt;&amp;#039;.  We have inserted &amp;lt;vp&amp;gt;nondeterm&amp;lt;/vp&amp;gt; to get around some compiler errors that we would later get, and instead we now get some warnings.  For now we will just ignore these warnings and in the sequel of this lesson you should just accept to write &amp;lt;vp&amp;gt;nondeterm&amp;lt;/vp&amp;gt; and also &amp;lt;vp&amp;gt;anyflow&amp;lt;/vp&amp;gt; where told.&lt;br /&gt;
&lt;br /&gt;
Back to the main subject.  Let us start with the proposition &amp;quot;John is the father of Bill&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Here we have two &amp;quot;things&amp;quot;: John and Bill, and a &amp;quot;relation&amp;quot; between these, namely that one is the father of the other.&lt;br /&gt;
In Visual Prolog I can formalize this proposition in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;).&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
father is a predicate/relation taking two arguments, where the second is the father of the first.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Notice&amp;#039;&amp;#039;&amp;#039; that &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;I &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;have chosen that the &amp;#039;&amp;#039;&amp;#039;second&amp;#039;&amp;#039;&amp;#039; person should be the father of the &amp;#039;&amp;#039;&amp;#039;first&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
I might as well have chosen it the other way around:  The order of the arguments is the choice of the &amp;quot;designer&amp;quot; of the formalization.&lt;br /&gt;
However, once you have chosen, you must be consistent.&lt;br /&gt;
So in &amp;#039;&amp;#039;&amp;#039;my&amp;#039;&amp;#039;&amp;#039; formalization the father must &amp;#039;&amp;#039;&amp;#039;always&amp;#039;&amp;#039;&amp;#039; be the second person.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Add this code to the project:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
class predicates&lt;br /&gt;
    father : (string Person, string Father) nondeterm anyflow.&lt;br /&gt;
clauses&lt;br /&gt;
    father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project.}}&lt;br /&gt;
&lt;br /&gt;
Now that we have a (tiny) &amp;quot;knowledge base&amp;quot;, we will try to find the answer to some questions.  Let&amp;#039;s first see the &amp;quot;magic&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
	runGoal() :-&lt;br /&gt;
		father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;),&lt;br /&gt;
		stdio::write(&amp;quot;Yes, John is the father of Bill&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the project.&lt;br /&gt;
&lt;br /&gt;
Then add one more clause like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
	runGoal() :-&lt;br /&gt;
		father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;),&lt;br /&gt;
		stdio::write(&amp;quot;Yes, John is the father of Bill&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
	runGoal() :-&lt;br /&gt;
		father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;),&lt;br /&gt;
		stdio::write(&amp;quot;Yes, John is the father of Sue&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And run the project again.&lt;br /&gt;
&lt;br /&gt;
Finally, modify add one more clauses like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
	runGoal() :-&lt;br /&gt;
		father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;),&lt;br /&gt;
		stdio::write(&amp;quot;Yes, John is the father of Bill&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
	runGoal() :-&lt;br /&gt;
		father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;),&lt;br /&gt;
		stdio::write(&amp;quot;Yes, John is the father of Sue&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
	runGoal() :-&lt;br /&gt;
		not(father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;)),&lt;br /&gt;
		stdio::write(&amp;quot;No, John is the not the father of Sue&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And run the project again.}}&lt;br /&gt;
&lt;br /&gt;
To understand what is going on we need to understand the concept of &amp;#039;&amp;#039;&amp;#039;succeed&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;fail&amp;#039;&amp;#039;&amp;#039;.  When we call &amp;lt;vp&amp;gt;father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;)&amp;lt;/vp&amp;gt; the call will &amp;#039;&amp;#039;&amp;#039;succeed&amp;#039;&amp;#039;&amp;#039;, because there is a clause that matches this call.  When we call &amp;lt;vp&amp;gt;father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;)&amp;lt;/vp&amp;gt; the call will &amp;#039;&amp;#039;&amp;#039;fail&amp;#039;&amp;#039;&amp;#039;, because the clauses for the father predicate cannot match this call.  &lt;br /&gt;
The call &amp;lt;vp&amp;gt;not(father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;))&amp;lt;/vp&amp;gt; will &amp;#039;&amp;#039;&amp;#039;succeed&amp;#039;&amp;#039;&amp;#039; because &amp;lt;vp&amp;gt;not&amp;lt;/vp&amp;gt; is  special predicate that succeeds if its argument fails and fails if the argument succeeds.&lt;br /&gt;
&lt;br /&gt;
Using the words &amp;#039;&amp;#039;succeed&amp;#039;&amp;#039; and &amp;#039;&amp;#039;fail&amp;#039; we can now explain the clauses.&lt;br /&gt;
&lt;br /&gt;
Let us first consider each of the three clauses individually (as if they were the only one)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first clause &amp;lt;vp&amp;gt;runGoal() :- father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;), stdio::write(&amp;quot;Yes, ...&amp;quot;).&amp;lt;/vp&amp;gt; works like this:  &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt; succeeds &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; &amp;lt;vp&amp;gt;father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;)&amp;lt;/vp&amp;gt; &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;lt;vp&amp;gt;stdio::write(&amp;quot;Yes, ...&amp;quot;)&amp;lt;/vp&amp;gt; succeeds, otherwise it fails.&lt;br /&gt;
&lt;br /&gt;
So when we call &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt; we will first run &amp;lt;vp&amp;gt;father(&amp;quot;Bill&amp;quot;, &amp;quot;John&amp;quot;)&amp;lt;/vp&amp;gt; and &amp;#039;&amp;#039;if&amp;#039;&amp;#039; that succeeds (which we know it will) we will call &amp;lt;vp&amp;gt;stdio::write(&amp;quot;Yes, ...&amp;quot;)&amp;lt;/vp&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The predicate &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; is a predicate that succeeds no matter which arguments it is called with and in addition it will also write the arguments to the standard output stream.&lt;br /&gt;
&lt;br /&gt;
So all in all, the first clause will &amp;#039;&amp;#039;&amp;#039;succeed&amp;#039;&amp;#039;&amp;#039; and also write &amp;lt;vp&amp;gt;&amp;quot;Yes, ...&amp;quot;&amp;lt;/vp&amp;gt; to the standard output stream.&lt;br /&gt;
&lt;br /&gt;
In the second clause we will first run &amp;lt;vp&amp;gt;father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;)&amp;lt;/vp&amp;gt; and since that call fails, the entire clause fails, and therefore we will &amp;#039;&amp;#039;not&amp;#039;&amp;#039; call &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; in this clause.&lt;br /&gt;
&lt;br /&gt;
In the third clause we first call &amp;lt;vp&amp;gt;not(father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;))&amp;lt;/vp&amp;gt;.  As mentioned above this call succeeds and therefore we will also call &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; in this clause.&lt;br /&gt;
&lt;br /&gt;
Now that we know how each clause works individually, lets look at the effect of having them all three.  This is actually the most unique feature of logical programming languages, but probably also the most tricky one to understand.  The idea is based on the logical &amp;quot;or&amp;quot;: to &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt; will succeed if the first clause &amp;quot;or&amp;quot; the second clause &amp;quot;or&amp;quot; the third clause succeeds.  It is true, but it is not sufficiently detailed when actually programming in Visual Prolog.  Here I will provide a much more detailed and operative description of how it works.&lt;br /&gt;
&lt;br /&gt;
When we invoke &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt;, which has three clauses.  We will first create a &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;backtrack&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; point to the two other clauses, and then excecute the first clause.&lt;br /&gt;
&lt;br /&gt;
A backtrack point is a &amp;quot;thing&amp;quot; that describes a place in our program where we had two alternative ways to fulfill our goal.  We do one thing but make a note about the other possibility.  If we at some point fail, we backtrack to the place we noted in the most recent backtrack point we created and follow the alternative way we noted in the backtrack point.  (That backtrack point is then used and thus discarded).&lt;br /&gt;
&lt;br /&gt;
So with all three &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt; clauses we will first create a backtrack point to the two last clauses and then execute the first clause.  As discussed above the first clause will succeed, so we will return from &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt; to the place in &amp;lt;vp&amp;gt;run()&amp;lt;/vp&amp;gt; where &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt; was called from, but we have also created a backtrack point to the two last clauses of &amp;lt;vp&amp;gt;runGoal()&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The code we wrote in the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clause will (without going into the datails) has the effect that we backtrack according to our backtrack point, so after returning from runGoal the first time we will backtrack to the last two &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clauses.&lt;br /&gt;
&lt;br /&gt;
When we backtrack to the last two clauses there is a choice between the second and the third clause, so again a backtrack point is created, this time to the third clause, and then the second clause is executed.&lt;br /&gt;
&lt;br /&gt;
As mentioned before the second clause will fail in the &amp;lt;vp&amp;gt;not(father(&amp;quot;Sue&amp;quot;, &amp;quot;John&amp;quot;))&amp;lt;/vp&amp;gt; call, when this happens we will again backtrack to where the latest backtrack point says, i.e. to the third &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause.  The third clause is the last clause so here we don&amp;#039;t have a choice point and therefore we do not have any more backtrack points left.&lt;br /&gt;
&lt;br /&gt;
The third clause will execute as described above and &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; will return to then &amp;lt;vp&amp;gt;run()&amp;lt;/vp&amp;gt; clause, and with no more backtrack points &amp;lt;vp&amp;gt;run()&amp;lt;/vp&amp;gt; will finish and eventually the entire program will finish.&lt;br /&gt;
&lt;br /&gt;
Notice that we backtracked two times in this program:&lt;br /&gt;
&lt;br /&gt;
* The first time we backtracked back into a predicate that had already returned one time, and therefore a single call to &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; returned twice to &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt;&lt;br /&gt;
*  The second backtrack was from the nested call to father in the second &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause to the third &amp;lt;vp&amp;gt;runGoal&amp;lt;/vp&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
Summary&lt;br /&gt;
&lt;br /&gt;
* Calls can succeed or fail.&lt;br /&gt;
* Whenever there is a choice point a backtrack point is created to the second choice and the first choice is pursued.&lt;br /&gt;
* When a predicate fails program control is backtracked to the latest backtrack point.&lt;br /&gt;
* Backtrack may &amp;quot;jump&amp;quot; out from nested calls &lt;br /&gt;
* Backtracking may also &amp;quot;jump&amp;quot; back  into already succeeded calls&lt;br /&gt;
* So as a result of backtracking a certain predicate call may succeed/return &amp;#039;&amp;#039;&amp;#039;several&amp;#039;&amp;#039;&amp;#039; times.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Output_arguments&amp;diff=4964</id>
		<title>Lessons/Output arguments</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Output_arguments&amp;diff=4964"/>
		<updated>2024-10-11T07:41:55Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: spelling mistake&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In the {{Lesson|Functions}} lesson we created a function, i.e. a predicate that returned a value.  Here we will look at output parameters, which is another way to let data flow outwards.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Add this code to a console project:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
class predicates&lt;br /&gt;
    nowDateAndTime : (string Date [out], string Time [out]).&lt;br /&gt;
clauses&lt;br /&gt;
    nowDateAndTime(Date, Time) :-&lt;br /&gt;
        Now = time::now(),&lt;br /&gt;
        Date = Now:formatShortDate(),&lt;br /&gt;
        Time = Now:formatTime().&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project, and answer &amp;quot;Yes&amp;quot; to adding the &amp;#039;&amp;#039;&amp;#039;...time.ph&amp;#039;&amp;#039;&amp;#039; include statement.}}&lt;br /&gt;
&lt;br /&gt;
The first thing to notice here is the use of &amp;lt;vp&amp;gt;[out]&amp;lt;/vp&amp;gt; in the predicate declaration, this &amp;quot;mark&amp;quot; indicates that the corresponding argument is an output argument rather than an input argument.&lt;br /&gt;
&lt;br /&gt;
In the clause we still have a &amp;quot;position&amp;quot; corresponding to that argument, but this time we have to &amp;quot;calculate&amp;quot; and return a value.  So in the clause above &amp;lt;vp&amp;gt;Date&amp;lt;/vp&amp;gt; and &amp;lt;vp&amp;gt;Time&amp;lt;/vp&amp;gt; does not have a value when the body starts to execute, it is our responsibility to create bind values to these variables. &lt;br /&gt;
&lt;br /&gt;
In the clause body we call the function &amp;lt;vp&amp;gt;now&amp;lt;/vp&amp;gt; on the class &amp;lt;vp&amp;gt;time&amp;lt;/vp&amp;gt; this function returns a time &amp;#039;&amp;#039;object&amp;#039;&amp;#039; that represents the time the function was called.  Here we will not go into details about objects, but the next two lines of code shows that objects have predicates associated with them and that these are referenced these using a single colon: &amp;lt;vp&amp;gt;&amp;lt;object&amp;gt;:&amp;lt;predicate&amp;gt;&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;vp&amp;gt;time&amp;lt;/vp&amp;gt; object represents a time and date, and in the last two lines we &amp;quot;request&amp;quot; the date using the short format and the time formatted as a string.  What exactly these functions does depends on the users settings on the computer (i.e. the users locale settings).&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the run clause like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        nowDateAndTime(NowDate, NowTime),&lt;br /&gt;
        stdio::writef(&amp;quot;The time is now % and it is the %.\n&amp;quot;, NowTime, NowDate).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the project.}}&lt;br /&gt;
&lt;br /&gt;
Sometimes you will accidentally use a single colon where you intended to use two and vice versa:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Try using a single colon instead of two and build the project and examine the error message.  Revert the problem and try the the opposite error.  End without errors.}}&lt;br /&gt;
&lt;br /&gt;
Output arguments can also be used in functions, and together with input arguments.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update &amp;lt;vp&amp;gt;nowDateAndTime&amp;lt;/vp&amp;gt; to be a &amp;#039;&amp;#039;&amp;#039;function&amp;#039;&amp;#039;&amp;#039; that returns the date as an output argument and the time as the function return value.&lt;br /&gt;
&lt;br /&gt;
Notice the error message you get if you don&amp;#039;t update the call in the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
Also update the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clause and run the program.}}&lt;br /&gt;
&lt;br /&gt;
Summary:&lt;br /&gt;
&lt;br /&gt;
* Output arguments are declared using the &amp;lt;vp&amp;gt;[out]&amp;lt;/vp&amp;gt; attribute.&lt;br /&gt;
* An output argument is unbound when the clause &amp;lt;vp&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/vp&amp;gt; is entered and must be bound when the predicate returns.&lt;br /&gt;
* There is something called objects.&lt;br /&gt;
* Objects are values that can be passed around and held in variables.&lt;br /&gt;
* Objects have predicates associated and these are referenced with single colon: &amp;lt;vp&amp;gt;&amp;lt;object&amp;gt;:&amp;lt;predicate&amp;gt;&amp;lt;/vp&amp;gt; (predicates in classes are referenced using a double-colon).&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Projects&amp;diff=4963</id>
		<title>Lessons/Projects</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Projects&amp;diff=4963"/>
		<updated>2024-10-11T07:40:19Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: small spelling mistakes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Visual Prolog &amp;#039;&amp;#039;project&amp;#039;&amp;#039; represents an executable or DLL programmed in Visual Prolog.  You can open a project in the [[IDE|IDE (Integrated Development Environment)]] and work on that project (i.e. executable/DLL).&lt;br /&gt;
&lt;br /&gt;
The IDE will remember a list of the projects it has opened, so that you can easily reopen one of your projects.  You can open several projects in each their IDE and work on them in parallel (should you want to).&lt;br /&gt;
&lt;br /&gt;
When you have a project open in the IDE you can navigate to the source files that the target (i.e. executable/DLL) is built from, and you can edit them.  In the IDE you can also build, execute and debug the target.&lt;br /&gt;
&lt;br /&gt;
So your main interaction with the project will be through the IDE.  The top-level information about the project is described in a project file (with extension &amp;#039;&amp;#039;&amp;#039;vipprj&amp;#039;&amp;#039;&amp;#039;).  The IDE will maintain the project file, and you will not need to look into the file.  But actually the project file is relatively easy to understand when you are familiar with the concepts of a project.&lt;br /&gt;
&lt;br /&gt;
When you create a new project you give it a name and decide which directory that should contain the project.  The project file and several other files will be created in this directory (and optionally sub-directories).  You can choose among project templates for GUI programs, command line programs, etc.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|&lt;br /&gt;
Create a &amp;#039;&amp;#039;&amp;#039;console&amp;#039;&amp;#039;&amp;#039; project in the IDE.}}&lt;br /&gt;
&lt;br /&gt;
After the project has been created it is automatically built (compiled, linked, etc).  This will produce an initial version of your target. Since the project is just created the target is not really interesting at this point, but a side effect of building a project is that the compiler will gather a lot of &amp;#039;&amp;#039;browse&amp;#039;&amp;#039; information about the entities in the program.&lt;br /&gt;
&lt;br /&gt;
The browse information enables the IDE to provide a lot of ways to navigate around in your code.  In the project tree there will be a lot of nodes corresponding to the entities in your program (including what is included from [[PFC| PFC (Prolog Foundation Classes]]).  And in the &amp;#039;&amp;#039;&amp;#039;Go to&amp;#039;&amp;#039;&amp;#039; menu you will find lots of navigation means most of which are based on the browse information.&lt;br /&gt;
&lt;br /&gt;
Browse information becomes inaccurate when you edit files, because editing changed the positions where things are located.  But upon a successful build of the project the browse information will again be accurate.  Unsuccessful builds may however make some useful browse information disappear until the build is again successful.  Therefore it is advisable to try to keep code as compilable as possible and build regularly.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|&lt;br /&gt;
Even though you currently does not know much about Visual Prolog examine the project tree in the project you created above, and try navigating around in it using the different entries in the &amp;#039;&amp;#039;&amp;#039;Go to&amp;#039;&amp;#039;&amp;#039; menu.  Try to figure out what the different things do.  And notice that many things have short-cut keys.}}&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|&lt;br /&gt;
Watch the [https://www.visual-prolog.com/video/HelloWorld/default.htm Hello World!] video tutorial, which demonstrates the basic IDE features.  The IDE in the video is from the older Visual Prolog version 7.3, so there are deviations from the current IDE, but the basics is the same and most of the details are also the same.}}&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|&lt;br /&gt;
Read the tutorial [[Ide/Environment Overview]] which contains much more detailed information about the IDE.  You may not get the full benefit from this tutorial now.  So it may be a good idea to read it again at some later point.}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Hello_World!&amp;diff=4962</id>
		<title>Lessons/Hello World!</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Hello_World!&amp;diff=4962"/>
		<updated>2024-10-11T07:37:33Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: a few spelling mistakes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this lesson we will just write some code disregarding the finer details.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Create a console project.&lt;br /&gt;
&lt;br /&gt;
Double-click the &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; file in the project tree to open it in an editor, and update the &amp;lt;vp&amp;gt;run clauses&amp;lt;/vp&amp;gt; to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        stdio::write(&amp;quot;Hello World!\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the program using &amp;#039;&amp;#039;&amp;#039;Build -&amp;gt; Run in window Alt+F5&amp;#039;&amp;#039;&amp;#039;.}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; file contains other stuff, which we will currently disregard, and focus solely on the &amp;lt;vp&amp;gt;run clauses&amp;lt;/vp&amp;gt; you just wrote.&lt;br /&gt;
&lt;br /&gt;
First we have the keyword &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt;, which simply indicates that what comes after are &amp;#039;&amp;#039;&amp;#039;clauses&amp;#039;&amp;#039;&amp;#039;.  Clauses is where the actual running code is written.&lt;br /&gt;
&lt;br /&gt;
In this text I will use words like &amp;quot;clause&amp;quot; and &amp;quot;predicate&amp;quot;, which all have their origin in formal logic, but for the moment we will simply treat them as the names that happens to be chosen for things in a Prolog program.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt; are used to define &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;, where a &amp;#039;&amp;#039;predicate&amp;#039;&amp;#039; is a Prolog routine/subroutine/function/procedure (dear child has many names)&lt;br /&gt;
&lt;br /&gt;
This particular clause defines a predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; which takes no arguments (indicated by the empty parentheses &amp;lt;vp&amp;gt;()&amp;lt;/vp&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
After the &amp;lt;vp&amp;gt;:-&amp;lt;/vp&amp;gt; token we have the code that will be executed when &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is invoked/called.&lt;br /&gt;
&lt;br /&gt;
In this case we call a predicate named &amp;lt;vp&amp;gt;write&amp;lt;/vp&amp;gt; which is defined in the &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; named &amp;lt;vp&amp;gt;stdio&amp;lt;/vp&amp;gt;.  We will discuss classes later for now we will just consider &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; as &amp;quot;a long compound name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We supply one argument, i.e. the string literal &amp;lt;vp&amp;gt;&amp;quot;Hello World!\n&amp;quot;&amp;lt;/vp&amp;gt;, to the &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; predicate.  Notice that \n in the string literal represents a line shift.&lt;br /&gt;
&lt;br /&gt;
The clause is terminated by a period (i.e. &amp;lt;vp&amp;gt;.&amp;lt;/vp&amp;gt;).  Period is used as terminator for many kinds of entities in Visual Prolog.&lt;br /&gt;
&lt;br /&gt;
The predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is called when the program is run, and acts as our entry point to the program.  Actually, the real entry point is the &amp;lt;vp&amp;gt;goal&amp;lt;/vp&amp;gt; a further down in the main.pro file, but that entry point is used to make varous initializations, corresponding clean-up, etc and will call the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate in the right spot, so run can act like your entry point.&lt;br /&gt;
&lt;br /&gt;
So when the program is run the predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; in &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; will be called and this will (here) call &lt;br /&gt;
&amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; with the argument &amp;lt;vp&amp;gt;&amp;quot;Hello World!\n&amp;quot;&amp;lt;/vp&amp;gt;, as a result &amp;#039;&amp;#039;Hello World!&amp;#039;&amp;#039; and a line shift will be written to the console window.&lt;br /&gt;
&lt;br /&gt;
Actually, &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; writes to the standard output stream, which in a console program is initialized to be the console window.  In a default GUI program the standard output stream will write to a message window, but the standard output stream is under programmer control, so what happens when you call &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; will depend of what has taken place in the program.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
* The actual running code is in &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt;&lt;br /&gt;
* &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt; is the Visual Prolog name for routines/subroutines/functions/procedures.&lt;br /&gt;
* Predicates are organized in classes, and predicates from other classes is referenced using &amp;lt;vp&amp;gt;&amp;lt;class&amp;gt;::&amp;lt;predicate&amp;gt;&amp;lt;/vp&amp;gt;.&lt;br /&gt;
* The &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate in &amp;lt;vp&amp;gt;main.pro&amp;lt;/vp&amp;gt; is the (effective) entry to a program.&lt;br /&gt;
* &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; can write to the standard output stream&lt;br /&gt;
&lt;br /&gt;
Now let us extend the program with an extra predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Add this code below the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clauses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
class predicates&lt;br /&gt;
    advancedHello : (string Name).&lt;br /&gt;
clauses&lt;br /&gt;
    advancedHello(Name) :-&lt;br /&gt;
        stdio::writef(&amp;quot;Hello %!\n&amp;quot;, Name).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project using &amp;#039;&amp;#039;&amp;#039;Build -&amp;gt; Build Ctrl+Shift+B&amp;#039;&amp;#039;&amp;#039;}}&lt;br /&gt;
&lt;br /&gt;
When you build the project you will get a warning stating that the predicate &amp;lt;vp&amp;gt;main::advancedHello&amp;lt;/vp&amp;gt; is an unused local predicate.  Which is completely correct; we haven&amp;#039;t used it for anything.  But let us &amp;quot;decipher&amp;quot; it before we go any further.&lt;br /&gt;
&lt;br /&gt;
We notice that we again have a clause in a &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt; section.  The clause is for a predicate named &amp;lt;vp&amp;gt; advancedHello&amp;lt;/vp&amp;gt; that takes one argument called &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt;.  &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; is a variable, a variable starts with an uppercase letter and will be green in the editor (variables can also start with an underscore, but we will discuss that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; acts as a formal parameter representing the actual argument used in the call to &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt;.  In this clause we call &amp;lt;vp&amp;gt;stdio::writef&amp;lt;/vp&amp;gt; which is a more advanced &amp;quot;writer&amp;quot; predicate.  The first argument to &amp;lt;vp&amp;gt;writef&amp;lt;/vp&amp;gt; is a format string, which contains a %-character, what happens when &amp;lt;vp&amp;gt;writef&amp;lt;/vp&amp;gt; is called is that the actual value of &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; is substituted into the format string in the place where the %-character is and then the resulting string is written to the standard output.&lt;br /&gt;
&lt;br /&gt;
This time we also have a &amp;lt;vp&amp;gt;class predicates&amp;lt;/vp&amp;gt; section containing a declaration of the &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt; predicate.  This particular declaration declares &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt; as a class predicate which takes one argument which must be a string.  &lt;br /&gt;
&lt;br /&gt;
In the predicate declaration the argument also have the name &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; but in the declaration the name is mainly intended for documentation purposes.  The variable name in the declaration and in the clauses can be different, or you can remove it completely from the declaration.  I recommend that you always have variable names here and that you use variable names that will make it clearer for the user of the predicate what the arguments represents.&lt;br /&gt;
&lt;br /&gt;
What it means to be a &amp;#039;&amp;#039;class&amp;#039;&amp;#039; predicate and what else a predicate can be is discussed elsewhere/later.  But before we leave the subject try this little experiment:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Remove the word &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; from &amp;lt;vp&amp;gt;class predicates&amp;lt;/vp&amp;gt; in the declaration of advancedHello. And then build the project.&lt;br /&gt;
&lt;br /&gt;
Notice the error message and remember that you get this message when you have forgotten to write &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; in front of &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then insert &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; again and build the project again.}}&lt;br /&gt;
&lt;br /&gt;
Now that we have the advancedHello predicate we can use it in our &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the run clause to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        advancedHello(&amp;quot;Dear&amp;quot;),&lt;br /&gt;
        advancedHello(&amp;quot;World&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
Run the project in a window.}}&lt;br /&gt;
&lt;br /&gt;
The clause should be understandable, I just want to highlight that we have used &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; to separate the two invocations of &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt;: &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; to separate, &amp;#039;&amp;#039;&amp;#039;period&amp;#039;&amp;#039;&amp;#039; to terminate. I will give a little prediction:  Later when you are familiar with Visual Prolog you will from time to time make syntax errors and (the prediction) 9 out of 10 times the syntax error will concern &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; and/or &amp;#039;&amp;#039;&amp;#039;period&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
* Predicates must have a declaration (&amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is also declared we just havn&amp;#039;t looked at its declaration).&lt;br /&gt;
* Arguments in predicates declarations can be given names that clarify the meaning if the arguments.&lt;br /&gt;
* &amp;lt;vp&amp;gt;stdio::writef&amp;lt;/vp&amp;gt; writes text to the standard output stream using a format string.&lt;br /&gt;
* calls are separated by comma and clauses (and predicate declarations) are terminated by period.&lt;br /&gt;
* If I get a syntax error it is likely to be related to comma or period.&lt;br /&gt;
* A certain other error message (can you recall it) probably means that I have forgotten to write &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; in front of &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Hello_World!&amp;diff=4961</id>
		<title>Lessons/Hello World!</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Hello_World!&amp;diff=4961"/>
		<updated>2024-10-10T14:06:12Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: Fixed bold formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this lesson we will just write some code disregarding the finer details.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Create a console project.&lt;br /&gt;
&lt;br /&gt;
Double-click the &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; file in the project tree to open it in an editor, and update the &amp;lt;vp&amp;gt;run clauses&amp;lt;/vp&amp;gt; to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        stdio::write(&amp;quot;Hello World!\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the program using &amp;#039;&amp;#039;&amp;#039;Build -&amp;gt; Run in window Alt+F5&amp;#039;&amp;#039;&amp;#039;.}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; file contains other stuff, which we will currently disregard, and focus solely on the &amp;lt;vp&amp;gt;run clauses&amp;lt;/vp&amp;gt; you just wrote.&lt;br /&gt;
&lt;br /&gt;
First we have the keyword &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt;, which simly indicates that what comes after are &amp;#039;&amp;#039;&amp;#039;clauses&amp;#039;&amp;#039;&amp;#039;.  Clauses is where the actual running code is written.&lt;br /&gt;
&lt;br /&gt;
In this text I will use words like &amp;quot;clause&amp;quot; and &amp;quot;predicate&amp;quot;, which all have their origin in formal logic, but for the moment we will simply treat them as the names that happens to be chosen for things in a Prolog program.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt; are used to define &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;, where a &amp;#039;&amp;#039;predicate&amp;#039;&amp;#039; is a Prolog routine/subroutine/function/procedure (dear child has many names)&lt;br /&gt;
&lt;br /&gt;
This particular clause defines a predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; which takes no arguments (indicated by the empty parentheses &amp;lt;vp&amp;gt;()&amp;lt;/vp&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
After the &amp;lt;vp&amp;gt;:-&amp;lt;/vp&amp;gt; token we have the code that will be executed when &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is invoked/called.&lt;br /&gt;
&lt;br /&gt;
In this case we call a predicate named &amp;lt;vp&amp;gt;write&amp;lt;/vp&amp;gt; which is defined in the &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; named &amp;lt;vp&amp;gt;stdio&amp;lt;/vp&amp;gt;.  We will discuss classes later for now we will just consider &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; as &amp;quot;a long compound name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We supply one argument, i.e. the string literal &amp;lt;vp&amp;gt;&amp;quot;Hello World!\n&amp;quot;&amp;lt;/vp&amp;gt;, to the &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; predicate.  Notice that \n in the string literal represents a line shift.&lt;br /&gt;
&lt;br /&gt;
The clause is terminated by a period (i.e. &amp;lt;vp&amp;gt;.&amp;lt;/vp&amp;gt;).  Period is used as terminator for many kinds of entities in Visual Prolog.&lt;br /&gt;
&lt;br /&gt;
The predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is called when the program is run, and acts as our entry point to the program.  Actually, the real entry point is the &amp;lt;vp&amp;gt;goal&amp;lt;/vp&amp;gt; a further down in the main.pro file, but that entry point is used to make varous initializations, corresponding clean-up, etc and will call the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate in the right spot, so run can act like your entry point.&lt;br /&gt;
&lt;br /&gt;
So when the program is run the predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; in &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; will be called and this will (here) call &lt;br /&gt;
&amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; with the argument &amp;lt;vp&amp;gt;&amp;quot;Hello World!\n&amp;quot;&amp;lt;/vp&amp;gt;, as a result &amp;#039;&amp;#039;Hello World!&amp;#039;&amp;#039; and a line shift will be written to the console window.&lt;br /&gt;
&lt;br /&gt;
Actually, &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; writes to the standard output stream, which in a console program is initialized to be the console window.  In a default GUI program the standard output stream will write to a message window, but the standard output stream is under programmer control, so what happens when you call &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; will depend of what has taken place in the program.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
* The actual running code is in &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt;&lt;br /&gt;
* &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt; is the Visual Prolog name for routines/subroutines/functions/procedures.&lt;br /&gt;
* Predicates are organized in classes, and predicates from other classes is referenced using &amp;lt;vp&amp;gt;&amp;lt;class&amp;gt;::&amp;lt;predicate&amp;gt;&amp;lt;/vp&amp;gt;.&lt;br /&gt;
* The &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate in &amp;lt;vp&amp;gt;main.pro&amp;lt;/vp&amp;gt; is the (effective) entry to a program.&lt;br /&gt;
* &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; can write to the standard output stream&lt;br /&gt;
&lt;br /&gt;
Now let us extend the program with an extra predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Add this code below the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clauses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
class predicates&lt;br /&gt;
    advancedHello : (string Name).&lt;br /&gt;
clauses&lt;br /&gt;
    advancedHello(Name) :-&lt;br /&gt;
        stdio::writef(&amp;quot;Hello %!\n&amp;quot;, Name).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project using &amp;#039;&amp;#039;&amp;#039;Build -&amp;gt; Build Ctrl+Shift+B&amp;#039;&amp;#039;&amp;#039;}}&lt;br /&gt;
&lt;br /&gt;
When you build the project you will get a warning stating that the predicate &amp;lt;vp&amp;gt;main::advancedHello&amp;lt;/vp&amp;gt; is an unused local predicate.  Which is completely correct; we haven&amp;#039;t used it for anything.  But let us &amp;quot;decipher&amp;quot; it before we go any further.&lt;br /&gt;
&lt;br /&gt;
We notice that we again have a clause in a &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt; section.  The clause is for a predicate named &amp;lt;vp&amp;gt; advancedHello&amp;lt;/vp&amp;gt; that takes one argument called &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt;.  &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; is a variable, a variable starts with an uppercase letter and will be green in the editor (variables can also start with an underscore, but we will discuss that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; acts as a formal parameter representing the actual argument used in the call to &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt;.  In this clause we call &amp;lt;vp&amp;gt;stdio::writef&amp;lt;/vp&amp;gt; which is a more advanced &amp;quot;writer&amp;quot; predicate.  The first argument to &amp;lt;vp&amp;gt;writef&amp;lt;/vp&amp;gt; is a format string, which contains a %-character, what happens when &amp;lt;vp&amp;gt;writef&amp;lt;/vp&amp;gt; is called is that the actual value of &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; is substituted into the format string in the place where the %-character is and then the resulting string is written to the standard output.&lt;br /&gt;
&lt;br /&gt;
This time we also have a &amp;lt;vp&amp;gt;class predicates&amp;lt;/vp&amp;gt; section containing a declaration of the &amp;lt;vp&amp;gt;advacedHello&amp;lt;/vp&amp;gt; predicate.  This perticular declaration declares &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt; as a class predicate which takes one argument which must be a string.  &lt;br /&gt;
&lt;br /&gt;
In the predicate declaration the argument also have the name &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; but in the declaration the name is mainly intended for documentation purposes.  The variable name in the declaration and in the clauses can be different, or you can remove it completely from the declaration.  I recommend that you always have variable names here and that you use variable names that will make it clearer for the user of the predicate what the arguments represents.&lt;br /&gt;
&lt;br /&gt;
What it means to be a &amp;#039;&amp;#039;class&amp;#039;&amp;#039; predicate and what else a predicate can be is discussed elsewhere/later.  But before we leave the subject try this little experiement:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Remove the word &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; from &amp;lt;vp&amp;gt;class predicates&amp;lt;/vp&amp;gt; in the declaration of advancedHello. And then build the project.&lt;br /&gt;
&lt;br /&gt;
Notice the error message and remember that you get this message when you have forgotten to write &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; in front of &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then insert &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; again and build the project again.}}&lt;br /&gt;
&lt;br /&gt;
Now that we have the advancedHello predicate we can use it in our &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the run clause to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        advancedHello(&amp;quot;Dear&amp;quot;),&lt;br /&gt;
        advancedHello(&amp;quot;World&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
Run the project in a window.}}&lt;br /&gt;
&lt;br /&gt;
The clause should be understandable, I just want to highlight that we have used &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; to separate the two invocations of &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt;: &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; to separate, &amp;#039;&amp;#039;&amp;#039;period&amp;#039;&amp;#039;&amp;#039; to terminate. I will give a little prediction:  Later when you are familiar with Visual Prolog you will from time to time make syntax errors and (the prediction) 9 out of 10 times the syntax error will concern &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; and/or &amp;#039;&amp;#039;&amp;#039;period&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
* Predicates must have a declaration (&amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is also declared we just havn&amp;#039;t looked at its declaration).&lt;br /&gt;
* Arguments in predicates declarations can be given names that clarify the meaning if the arguments.&lt;br /&gt;
* &amp;lt;vp&amp;gt;stdio::writef&amp;lt;/vp&amp;gt; writes text to the standard output stream using a format string.&lt;br /&gt;
* calls are separated by comma and clauses (and predicate declarations) are terminated by period.&lt;br /&gt;
* If I get a syntax error it is likely to be related to comma or period.&lt;br /&gt;
* A certain other error message (can you recall it) probably means that I have forgotten to write &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; in front of &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
	<entry>
		<id>https://wiki.visual-prolog.com/index.php?title=Lessons/Hello_World!&amp;diff=4960</id>
		<title>Lessons/Hello World!</title>
		<link rel="alternate" type="text/html" href="https://wiki.visual-prolog.com/index.php?title=Lessons/Hello_World!&amp;diff=4960"/>
		<updated>2024-10-10T14:03:13Z</updated>

		<summary type="html">&lt;p&gt;Adam Rose: Clarification&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this lesson we will just write some code disregarding the finer details.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Create a console project.&lt;br /&gt;
&lt;br /&gt;
Double-click the &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; file in the project tree to open it in an editor, and update the &amp;lt;vp&amp;gt;run clauses&amp;lt;/vp&amp;gt; to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        stdio::write(&amp;quot;Hello World!\n&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the program using &amp;#039;&amp;#039;&amp;#039;Build -&amp;gt; Run in window Alt+F5&amp;#039;&amp;#039;&amp;#039;.}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; file contains other stuff, which we will currently disregard, and focus solely on the &amp;lt;vp&amp;gt;run clauses&amp;lt;/vp&amp;gt; you just wrote.&lt;br /&gt;
&lt;br /&gt;
First we have the keyword &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt;, which simly indicates that what comes after are &amp;#039;&amp;#039;&amp;#039;clauses&amp;#039;&amp;#039;&amp;#039;.  Clauses is where the actual running code is written.&lt;br /&gt;
&lt;br /&gt;
In this text I will use words like &amp;quot;clause&amp;quot; and &amp;quot;predicate&amp;quot;, which all have their origin in formal logic, but for the moment we will simply treat them as the names that happens to be chosen for things in a Prolog program.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt; are used to define &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;, where a &amp;#039;&amp;#039;predicate&amp;#039;&amp;#039; is a Prolog routine/subroutine/function/procedure (dear child has many names)&lt;br /&gt;
&lt;br /&gt;
This particular clause defines a predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; which takes no arguments (indicated by the empty parentheses &amp;lt;vp&amp;gt;()&amp;lt;/vp&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
After the &amp;lt;vp&amp;gt;:-&amp;lt;/vp&amp;gt; token we have the code that will be executed when &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is invoked/called.&lt;br /&gt;
&lt;br /&gt;
In this case we call a predicate named &amp;lt;vp&amp;gt;write&amp;lt;/vp&amp;gt; which is defined in the &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; named &amp;lt;vp&amp;gt;stdio&amp;lt;/vp&amp;gt;.  We will discuss classes later for now we will just consider &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; as &amp;quot;a long compound name&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We supply one argument, i.e. the string literal &amp;lt;vp&amp;gt;&amp;quot;Hello World!\n&amp;quot;&amp;lt;/vp&amp;gt;, to the &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; predicate.  Notice that \n in the string literal represents a line shift.&lt;br /&gt;
&lt;br /&gt;
The clause is terminated by a period (i.e. &amp;lt;vp&amp;gt;.&amp;lt;/vp&amp;gt;).  Period is used as terminator for many kinds of entities in Visual Prolog.&lt;br /&gt;
&lt;br /&gt;
The predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is called when the program is run, and acts as our entry point to the program.  Actually, the real entry point is the &amp;lt;vp&amp;gt;goal&amp;lt;/vp&amp;gt; a further down in the main.pro file, but that entry point is used to make varous initializations, corresponding clean-up, etc and will call the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate in the right spot, so run can act like your entry point.&lt;br /&gt;
&lt;br /&gt;
So when the program is run the predicate &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; in &amp;#039;&amp;#039;&amp;#039;main.pro&amp;#039;&amp;#039;&amp;#039; will be called and this will (here) call &lt;br /&gt;
&amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; with the argument &amp;lt;vp&amp;gt;&amp;quot;Hello World!\n&amp;quot;&amp;lt;/vp&amp;gt;, as a result &amp;#039;&amp;#039;Hello World!&amp;#039;&amp;#039; and a line shift will be written to the console window.&lt;br /&gt;
&lt;br /&gt;
Actually, &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; writes to the standard output stream, which in a console program is initialized to be the console window.  In a default GUI program the standard output stream will write to a message window, but the standard output stream is under programmer control, so what happens when you call &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; will depend of what has taken place in the program.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
* The actual running code is in &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt;&lt;br /&gt;
* &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt; is the Visual Prolog name for routines/subroutines/functions/procedures.&lt;br /&gt;
* Predicates are organized in classes, and predicates from other classes is referenced using &amp;lt;vp&amp;gt;&amp;lt;class&amp;gt;::&amp;lt;predicate&amp;gt;&amp;lt;/vp&amp;gt;.&lt;br /&gt;
* The &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate in &amp;lt;vp&amp;gt;main.pro&amp;lt;/vp&amp;gt; is the (effective) entry to a program.&lt;br /&gt;
* &amp;lt;vp&amp;gt;stdio::write&amp;lt;/vp&amp;gt; can write to the standard output stream&lt;br /&gt;
&lt;br /&gt;
Now let us extend the program with an extra predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Add this code below the &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; clauses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
class predicates&lt;br /&gt;
    advancedHello : (string Name).&lt;br /&gt;
clauses&lt;br /&gt;
    advancedHello(Name) :-&lt;br /&gt;
        stdio::writef(&amp;quot;Hello %!\n&amp;quot;, Name).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the project using &amp;#039;&amp;#039;&amp;#039;Build -&amp;gt; Build Ctrl+Shift+B&amp;#039;&amp;#039;&amp;#039;}}&lt;br /&gt;
&lt;br /&gt;
When you build the project you will get a warning stating that the predicate &amp;lt;vp&amp;gt;main::advancedHello&amp;lt;/vp&amp;gt; is an unused local predicate.  Which is completely correct; we haven&amp;#039;t used it for anything.  But let us &amp;quot;decipher&amp;quot; it before we go any further.&lt;br /&gt;
&lt;br /&gt;
We notice that we again have a clause in a &amp;lt;vp&amp;gt;clauses&amp;lt;/vp&amp;gt; section.  The clause is for a predicate named &amp;lt;vp&amp;gt; advancedHello&amp;lt;/vp&amp;gt; that takes one argument called &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt;.  &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; is a variable, a variable starts with an uppercase letter and will be green in the editor (variables can also start with an underscore, but we will discuss that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; acts as a formal parameter representing the actual argument used in the call to &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt;.  In this clause we call &amp;lt;vp&amp;gt;stdio::writef&amp;lt;/vp&amp;gt; which is a more advanced &amp;quot;writer&amp;quot; predicate.  The first argument to &amp;lt;vp&amp;gt;writef&amp;lt;/vp&amp;gt; is a format string, which contains a %-character, what happens when &amp;lt;vp&amp;gt;writef&amp;lt;/vp&amp;gt; is called is that the actual value of &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; is substituted into the format string in the place where the %-character is and then the resulting string is written to the standard output.&lt;br /&gt;
&lt;br /&gt;
This time we also have a &amp;lt;vp&amp;gt;class predicates&amp;lt;/vp&amp;gt; section containing a declaration of the &amp;lt;vp&amp;gt;advacedHello&amp;lt;/vp&amp;gt; predicate.  This perticular declaration declares &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt; as a class predicate which takes one argument which must be a string.  &lt;br /&gt;
&lt;br /&gt;
In the predicate declaration the argument also have the name &amp;lt;vp&amp;gt;Name&amp;lt;/vp&amp;gt; but in the declaration the name is mainly intended for documentation purposes.  The variable name in the declaration and in the clauses can be different, or you can remove it completely from the declaration.  I recommend that you always have variable names here and that you use variable names that will make it clearer for the user of the predicate what the arguments represents.&lt;br /&gt;
&lt;br /&gt;
What it means to be a &amp;#039;&amp;#039;class&amp;#039;&amp;#039; predicate and what else a predicate can be is discussed elsewhere/later.  But before we leave the subject try this little experiement:&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Remove the word &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; from &amp;lt;vp&amp;gt;class predicates&amp;lt;/vp&amp;gt; in the declaration of advancedHello. And then build the project.&lt;br /&gt;
&lt;br /&gt;
Notice the error message and remember that you get this message when you have forgotten to write &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; in front of &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then insert &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; again and build the project again.}}&lt;br /&gt;
&lt;br /&gt;
Now that we have the advancedHello predicate we can use it in our &amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; predicate.&lt;br /&gt;
&lt;br /&gt;
{{Lessons/Exercise|Update the run clause to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;vip&amp;gt;&lt;br /&gt;
clauses&lt;br /&gt;
    run() :-&lt;br /&gt;
        advancedHello(&amp;quot;Dear&amp;quot;),&lt;br /&gt;
        advancedHello(&amp;quot;World&amp;quot;).&lt;br /&gt;
&amp;lt;/vip&amp;gt;&lt;br /&gt;
Run the project in a window.}}&lt;br /&gt;
&lt;br /&gt;
The clause should be understandable, I just want to highlight that we have used &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; to separate the two invocations of &amp;lt;vp&amp;gt;advancedHello&amp;lt;/vp&amp;gt;: &amp;#039;&amp;#039;&amp;#039;comma&amp;quot; to separate, &amp;#039;&amp;#039;&amp;#039;period&amp;#039;&amp;#039;&amp;#039; to terminate. I will give a little prediction:  Later when you are familiar with Visual Prolog you will from time to time make syntax errors and (the prediction) 9 out of 10 times the syntax error will concern &amp;#039;&amp;#039;&amp;#039;comma&amp;#039;&amp;#039;&amp;#039; and/or &amp;#039;&amp;#039;&amp;#039;period&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
* Predicates must have a declaration (&amp;lt;vp&amp;gt;run&amp;lt;/vp&amp;gt; is also declared we just havn&amp;#039;t looked at its declaration).&lt;br /&gt;
* Arguments in predicates declarations can be given names that clarify the meaning if the arguments.&lt;br /&gt;
* &amp;lt;vp&amp;gt;stdio::writef&amp;lt;/vp&amp;gt; writes text to the standard output stream using a format string.&lt;br /&gt;
* calls are separated by comma and clauses (and predicate declarations) are terminated by period.&lt;br /&gt;
* If I get a syntax error it is likely to be related to comma or period.&lt;br /&gt;
* A certain other error message (can you recall it) probably means that I have forgotten to write &amp;lt;vp&amp;gt;class&amp;lt;/vp&amp;gt; in front of &amp;lt;vp&amp;gt;predicates&amp;lt;/vp&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lessons|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>Adam Rose</name></author>
	</entry>
</feed>