<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<feed xmlns="http://www.w3.org/2005/Atom">

	<title>Planet Prolog</title>
	<link rel="self" href="http://www.cs.kuleuven.be/~toms/PlanetProlog/atom.xml"/>
	<link href="http://www.cs.kuleuven.be/~toms/PlanetProlog/"/>
	<id>http://www.cs.kuleuven.be/~toms/PlanetProlog/atom.xml</id>
	<updated>2012-05-16T15:23:45+00:00</updated>
	<generator uri="http://www.planetplanet.org/">Planet/2.0 +http://www.planetplanet.org</generator>

	<entry>
		<title type="html">List search in Prolog</title>
		<link href="http://stackoverflow.com/questions/10620756/list-search-in-prolog"/>
		<id>http://stackoverflow.com/q/10620756</id>
		<updated>2012-05-16T14:31:16+00:00</updated>
		<content type="html">&lt;p&gt;I'm trying to make a search in a list in Prolog, but I would like to start right at a certain position. Will I have to do that boring recursive search?&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;</content>
		<author>
			<name>Francisco de Gusmão</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Explanation of a prolog algorithm</title>
		<link href="http://stackoverflow.com/questions/10620011/explanation-of-a-prolog-algorithm"/>
		<id>http://stackoverflow.com/q/10620011</id>
		<updated>2012-05-16T14:12:22+00:00</updated>
		<content type="html">&lt;p&gt;This is an algorithm to append together 2 lists&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Domains
list= integer*

Predicates
nondeterm append(list, list, list)

Clauses
append([], List, List):-!.
append([H|L1], List2, [H|L3]) :-append(L1, List2, L3).

Goal
append([9,2,3,4], [-10,-5,6,7,8],Ot).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The result really is a list [9,2,3,4,-10,-5,6,7,8] and its saved in &quot;Ot&quot;&lt;/p&gt;

&lt;p&gt;My question is how does this work?
What i understand is that in every recursive call , in the first list , you get only the tail as a list ( thus reducing its size by 1 untill its [] ) , the second argument &quot;List2&quot; does not change at all , and the 3rd argument .. at first its [] and after each recursive call you get its tail , but since its [] , it stays [].&lt;/p&gt;

&lt;p&gt;So how comes that suddently in argument 3 (&quot;Ot&quot;) we have the appended list ?
Can someone explain this algorithm step by step ?&lt;/p&gt;</content>
		<author>
			<name>Jordashiro</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Simplified Travelling Salesman in Prolog</title>
		<link href="http://stackoverflow.com/questions/8318293/simplified-travelling-salesman-in-prolog"/>
		<id>http://stackoverflow.com/q/8318293</id>
		<updated>2012-05-16T13:53:27+00:00</updated>
		<content type="html">&lt;p&gt;I've looked through the similar questions but can't find anything that's relevant to my problem. I'm struggling to find an algorithm or set of 'loops' that will find a path from &lt;code&gt;CityA&lt;/code&gt; to &lt;code&gt;CityB&lt;/code&gt;, using a database of&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;distance(City1,City2,Distance)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;facts. What I've managed to do so far is below, but it always backtracks at &lt;code&gt;write(X),&lt;/code&gt; and then completes with the final iteration, which is what I want it to do but only to a certain extent.&lt;/p&gt;

&lt;p&gt;For example, I don't want it to print out any city names that are dead ends, or to use the final iteration. I want it to basically make a path from &lt;code&gt;CityA&lt;/code&gt; to &lt;code&gt;CityB&lt;/code&gt;, writing the name of the cities it goes to on the path.&lt;/p&gt;

&lt;p&gt;I hope somebody can help me!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;all_possible_paths(CityA, CityB) :-
    write(CityA),
    nl,
    loop_process(CityA, CityB).

loop_process(CityA, CityB) :- 
    CityA == CityB.
loop_process(CityA, CityB) :-
    CityA \== CityB,
    distance(CityA, X, _),
    write(X),
    nl,
    loop_process(X, CityB).
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>g.a.kilby</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Drawing paths in an OSM map</title>
		<link href="http://stackoverflow.com/questions/10618782/drawing-paths-in-an-osm-map"/>
		<id>http://stackoverflow.com/q/10618782</id>
		<updated>2012-05-16T12:42:32+00:00</updated>
		<content type="html">&lt;p&gt;In an experiment with Prolog I would like to use the data provided from &lt;a href=&quot;http://www.openstreetmap.org/&quot; rel=&quot;nofollow&quot;&gt;OSM&lt;/a&gt; to calculate, for example, the shortest path to traverse a collection of points of interest. I have an idea how to do that with Prolog, and even how to access my Prolog program from a Java servlet (responsible of rendering the map among other things).&lt;/p&gt;

&lt;p&gt;However, since I am new to OSM I still do not know how to let the users select a certain amount of nodes from the map, and how to answer (I mean, how to draw in the map) the shortest path to traverse them (given a user selected starting node). Could someone give me a hint about how I can ask, using an OSM map,  many points of interest from a user and later draw a path between them as an answer ?&lt;/p&gt;

&lt;p&gt;Thanks in advance!&lt;/p&gt;</content>
		<author>
			<name>Sergio</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog recursion stopping</title>
		<link href="http://stackoverflow.com/questions/10618204/prolog-recursion-stopping"/>
		<id>http://stackoverflow.com/q/10618204</id>
		<updated>2012-05-16T12:09:43+00:00</updated>
		<content type="html">&lt;p&gt;I try to make in Prolog function that will be have list of questions like&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; questions([[[What, are,you,doing,?],[Where,am,I,Incorrect,?]]]).
 answers([[Im,doing,exercise],[I,do,nothing]],[[You,are,incorrect,at,'..'],[i,dont,know]]]).
 wordkeys([[[Incorrect,50],[doing,20]]]).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I know it look really messy but I really need help and will be grateful.
Main function is checking which answer is the best (having biggest sum of keywords points).
My problem is that all look fine(made some write() to see what happening) till it go to last function here : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;count_pnt_keys()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Prolog checking all words if their equal but when is out from keywords should come back to function called it but its just 'no' . Maybe I should check if list is empty before I call again the same function with just Tail? How to do this?&lt;/p&gt;

&lt;p&gt;rules:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;count_pnt([],[],[]).
count_pnt([Ah|At],Keys,RList) :-      %choose one answer from answer list and go further
    count_pnt_word(Ah,Keys,Pnts),     %return sum of points for one answer
    count_ADD_POINT(RList,Pnts),      %not important here
    count_pnt(At,Keys,RList).         %call again with next question
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
count_pnt_word([],[],0)
count_pnt_word([Ah|At],Keys,Pnts) :-  %choose one WORD from answer and go further
    count_pnt_keys(Ah,Keys,Pnts),
    count_pnt_word(At,Keys,Pnts).     %call recursion with next word from answer
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
count_pnt_keys([],[],0)
count_pnt_keys(AWord,[Kh|Kt],Pnts) :- %check word with all keys for first question
    get_tail_h(Kh,KWORD,KPOINTS),     %just return head and tail from first key
    AWord==KWORD,                     %check if they are equal
    /*counting points*/ !,            %counting not important when end counting points go out to next
    count_pnt_keys(AWord,Kt,Pnts). %call again if not equal and try with next key
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and I call it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;test :-
write(AnswerFirst),
count_pnt(FirstPackOfAnswer,FirstPackofKeys,ReturnedListwithpoints),
write(ReturnedListwithpoints).
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>kajojeq</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">CILC2012 – Accepted Papers and Call for Participation</title>
		<link href="http://www.cs.nmsu.edu/ALP/2012/05/cilc2012-papers-accepted-and-call-for-participation/"/>
		<id>http://www.cs.nmsu.edu/ALP/?p=2012</id>
		<updated>2012-05-16T08:11:16+00:00</updated>
		<content type="html">&lt;h3&gt;CILC 2012 &amp;#8211; 9th Italian Convention on Computational Logic&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://www.dis.uniroma1.it/~cilc2012/program.html&quot;&gt;www.dis.uniroma1.it/~cilc2012&lt;/a&gt;&lt;br /&gt;
June 6-7, 2012, Università di Roma &amp;#8220;La Sapienza&amp;#8221;&lt;/p&gt;
&lt;h3&gt;OVERVIEW&lt;/h3&gt;
&lt;p&gt;The Italian Convention on Computational Logic is an annual event  organized by GULP (Gruppo ricercatori e Utenti Logic Programming), the  Italian association for Logic Programming affiliated to ALP (Association  for Logic Programming). Since 1986, the annual meeting organized by GULP  is the most important occasion for meeting and exchanging ideas and  experiences between users, researchers and developers, who work in the  field of computational logic. During its 26 years of recurrence, the  annual GULP meeting has continually widened its horizons from the field  of traditional logic programming to the more general areas of  declarative programming and its applications in various neighboring  fields, such as Artificial Intelligence or Deductive Databases. Also in  this year&amp;#8217;s convention, GULP wants to continue and possibly widen this  policy, using the general term Computational Logic for integrating the  various research fields, which use in direct or indirect, practical or  theoretical ways or just addresses the ideas or techniques of logic as a  tool for representation and calculation.&lt;/p&gt;
&lt;h3&gt;VENUE&lt;/h3&gt;
&lt;p&gt;CILC 2012 will be held at the Dipartimento di Ingegneria Informatica,  Automatica e Gestionale &amp;#8220;A. Ruberti&amp;#8221; (formerly, DIS: Dipartimento di  Informatica e Sistemistica) of Sapienza Università di Roma from June 6th  to June 7th, 2012, in co-location with DL 2012, NMR 2012, KR 2012, and  AI*IA 2012.&lt;br /&gt;
Details about how to find the CILC 2012 venue are available at &lt;a href=&quot;http://www.dis.uniroma1.it/~cilc2012/venue.html&quot;&gt;http://www.dis.uniroma1.it/~cilc2012/venue.html&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;REGISTRATION&lt;/h3&gt;
&lt;p&gt;The convention is an event organized by GULP. Participants have to be  members of GULP for 2012 (participants can join GULP at the event). Participants are invited to register as soon as possible in order to allow for a better organization of the event.&lt;/p&gt;
&lt;p&gt;Free passes to KR 2012 tutorials are available for a limited number of CILC 2012 registrants. This possibility is open only to those who are not registered for KR 2012. When registering, CILC 2012 participants are invited to express an interest in this possibility.&lt;/p&gt;
&lt;p&gt;Details about the registration are available at  &lt;a href=&quot;http://www.dis.uniroma1.it/~cilc2012/registration.html&quot;&gt;http://www.dis.uniroma1.it/~cilc2012/registration.html&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;PROGRAM  (and accepted papers)&lt;/h3&gt;
&lt;p&gt;The program is available here: &lt;a href=&quot;http://www.dis.uniroma1.it/~cilc2012/program.html&quot;&gt;http://www.dis.uniroma1.it/~cilc2012/program.html&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;ORGANIZATION&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Francesca Alessandra Lisi, Università degli Studi di Bari &amp;#8220;Aldo Moro&amp;#8221;, Italy (PC Chair)&lt;/li&gt;
&lt;li&gt; Fabio Patrizi, &amp;#8220;Sapienza&amp;#8221; Università di Roma, Italy (Local Organization Chair)&lt;/li&gt;
&lt;/ul&gt;</content>
		<author>
			<name>ALP Newsletter</name>
			<uri>http://www.cs.nmsu.edu/ALP</uri>
		</author>
		<source>
			<title type="html">Association for Logic Programming</title>
			<link rel="self" href="http://www.cs.nmsu.edu/ALP/feed/"/>
			<id>http://www.cs.nmsu.edu/ALP/feed/</id>
			<updated>2012-05-16T11:23:18+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Get list of sets where the sum of each set is X</title>
		<link href="http://stackoverflow.com/questions/10611585/get-list-of-sets-where-the-sum-of-each-set-is-x"/>
		<id>http://stackoverflow.com/q/10611585</id>
		<updated>2012-05-16T07:11:44+00:00</updated>
		<content type="html">&lt;p&gt;I'm trying to figure out how to generate a list of sets, where each set has a length of N and the sum of each set is X.&lt;/p&gt;

&lt;p&gt;I found this code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;num_split(0,[]).
num_split(N, [X | List]):-
   between(1,N,X),
   plus(X,Y,N),
   num_split(Y,List).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And I can use that to get a list of sets with sum X:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;num_split(6,List),length(List,5).
List = [1, 1, 1, 1, 2] ;
List = [1, 1, 1, 2, 1] ;
List = [1, 1, 2, 1, 1] ;
List = [1, 2, 1, 1, 1] ;
List = [2, 1, 1, 1, 1] ;
false.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The problem is that those are all permutations, and I'm looking for combinations. The output I'm looking for should be something like &lt;code&gt;get_combos(Sum,Length,List)&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;get_combos(6,2,List).
List = [5,1];
List = [4,2];
List = [3,3];
false.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Any pointers?&lt;/p&gt;</content>
		<author>
			<name>Sean Hagen</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">plan a route in prolog</title>
		<link href="http://stackoverflow.com/questions/10601238/plan-a-route-in-prolog"/>
		<id>http://stackoverflow.com/q/10601238</id>
		<updated>2012-05-15T22:42:17+00:00</updated>
		<content type="html">&lt;p&gt;What i wan to do is find a route with some givin facs. i've done some research and i allready know that i have to add a basic step and recursief step. that i've implemented but it does not work when i have to transfer. So if it are neighbours, it works, but not otherwise.&lt;/p&gt;

&lt;p&gt;this is what i have:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;p(zwolle,apeldoor,36).
p(apeldoorn,zutphen,22).
p(hengelo,zwolle,60).
p(zutphen,hengelo,45).
p(arnhem,apeldoorn,30).
p(arnhem,zutphen,24). 


%basic step
route(Begin,End,PastCitys):-
       not(member(End,PastCitys)),
   p(Begin,End,_).

%recursief
route(Begin,End,PastCitys):-
  p(Begin,Stepover,_),
      not(member(Stepover,PastCitys)),
  route(Stepover,End).

plan(Begin,End):-
   route(Begin,End,[Begin]).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;any help is welcome&lt;/p&gt;</content>
		<author>
			<name>Jorne De Blaere</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog: a(b,c) and a(X,Y):-a(Y,X), query a(c,b) returns infinite true?</title>
		<link href="http://stackoverflow.com/questions/10609324/prolog-ab-c-and-ax-y-ay-x-query-ac-b-returns-infinite-true"/>
		<id>http://stackoverflow.com/q/10609324</id>
		<updated>2012-05-15T22:20:39+00:00</updated>
		<content type="html">&lt;p&gt;Here is my knowledge base: &lt;/p&gt;

&lt;p&gt;a(b,c). 
a(X,Y):-a(Y,X). &lt;/p&gt;

&lt;p&gt;Here is my query: a(c,b).&lt;/p&gt;

&lt;p&gt;I am using SWI-Prolog. I thought that this query would lead to the program printing &quot;true&quot;. However, instead it prints &quot;true&quot; and continues to print true if I hit the semicolon... until FOREVER. &lt;/p&gt;

&lt;p&gt;Why doesn't it stop? &lt;/p&gt;

&lt;p&gt;My thoughts: First, X is bound to b and Y is bound to c. Then, prolog tests a(b,c) and finds that this is true. Therefore, a(c,b) is true as well and swi-prolog should print true once. However, since it prints true forever as long as I keep hitting that semicolon, this leads me to think that something recursive is going on. Where is this happening? Help! &lt;/p&gt;

&lt;p&gt;EDIT: More specifically my question is why does the program pause after each &quot;true&quot; and wait for me to press the semicolon or another key instead of just being done? If I have two predicates human(socrates) and mortal(X):-humans(X), the response to the query mortal(socrates) will be a single &quot;true&quot;. (Sorry if I failed to make this clear above.)&lt;/p&gt;</content>
		<author>
			<name>NullPointer</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Converting OSM data to Prolog facts?</title>
		<link href="http://stackoverflow.com/questions/10609483/converting-osm-data-to-prolog-facts"/>
		<id>http://stackoverflow.com/q/10609483</id>
		<updated>2012-05-15T22:05:32+00:00</updated>
		<content type="html">&lt;p&gt;For a small experiment, I would like to transform an exported &lt;a href=&quot;http://planet.openstreetmap.org/&quot; rel=&quot;nofollow&quot;&gt;OSM&lt;/a&gt; dataset from XML to Prolog.&lt;/p&gt;

&lt;p&gt;I know there are certain general purpose XML to Prolog converters (e.g., &lt;a href=&quot;http://www.techrepublic.com/whitepapers/pl4xml-an-swi-prolog-library-for-xml-data-management/2358643&quot; rel=&quot;nofollow&quot;&gt;Pl4Xml&lt;/a&gt;), but are these general purpose converters the best way to go for this problem ? probably someone knows about a library to convert OSM data to a &lt;strong&gt;convenient&lt;/strong&gt; representation in Prolog ?&lt;/p&gt;</content>
		<author>
			<name>Sergio</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Changing global stack size, GNU Prolog</title>
		<link href="http://stackoverflow.com/questions/10606400/changing-global-stack-size-gnu-prolog"/>
		<id>http://stackoverflow.com/q/10606400</id>
		<updated>2012-05-15T20:21:50+00:00</updated>
		<content type="html">&lt;p&gt;So I'm working with GNU Prolog on a bash server at my university and I need to increase the global stack size.&lt;/p&gt;

&lt;p&gt;I've tried compiling with the following options:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    gprolog --global-size 16384 --init-goal 'consult('test')'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where test is just a test.pl file I made for testing.  However, I still get the following exception&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    Fatal Error: global stack overflow (size: 8192 Kb, environment variable used: GLOBALSZ)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Which indicates that the size is still 8192 Kb.  Unfortunately I'm running GNU Prolog version 1.2.16 as that's what's on the server and I can't readily change it.  Is there anything I can do here?&lt;/p&gt;</content>
		<author>
			<name>BCsorba</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">search all paths and the shortest path for a graph - Prolog</title>
		<link href="http://stackoverflow.com/questions/2564058/search-all-paths-and-the-shortest-path-for-a-graph-prolog"/>
		<id>http://stackoverflow.com/q/2564058</id>
		<updated>2012-05-15T18:55:24+00:00</updated>
		<content type="html">&lt;p&gt;I have a problem in my code with turbo prolog wich search all paths and the shortest path for a graph between 2 nodes 
the problem that i have is to test if the node is on the list or not exactly in the clause of member 
and this is my code : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/*



           1    ---- b ----   3
           ---       |        ---
        ---          |             -----
      a              |5                  d
        ---          |             -----
            ---      |         ---
             2  ---  |     ---   4
                  -- c  --

for example we have for b---&amp;gt;c 
([b,c],5) , ([b,a,c],3) and ([b,d,c],7) : possible paths.
([b,a,c],3) : the shortest path.                                                        
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;*/&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DOMAINS
list=Symbol *
PREDICATES


distance(Symbol,Symbol)
    path1(Symbol,Symbol,list,integer)
    path(Symbol,Symbol,list,list,integer)
    distance(Symbol,list,integer)
    member(Symbol,list)
    shortest(Symbol,Symbol,list,integer)

CLAUSES 
    distance(a,b,1).
    distance(a,c,2).
    distance(b,d,3).
    distance(c,d,4).
    distance(b,c,5).
    distance(b,a,1).
    distance(c,a,2).
    distance(d,b,3).
    distance(d,c,4).
    distance(c,b,5).

    member(X,[X|T]).
member(X, [Y|T]) :- member(X, T).

absent(X,L) :-member(X, L),!,fail.
    absent(_,_).

/*find all paths*/
path1(X, Y, L, C):- path(X, Y, L, I, C).
path(X, X, [X], I, C) :- absent(X, I).
path(X, Y, [X|R], I, C) :- distance(X, Z, A) , absent(Z, I), 
   path(Z, Y, R, [X|I] ,C1) , C=C1+A .

/*to find the shortest path*/
shortest(X, Y, L, C):-path(X, Y, L, C),path(X, Y, L1, C1),C&amp;lt;C1.
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>user307320</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Pattern in prolog</title>
		<link href="http://stackoverflow.com/questions/10547033/pattern-in-prolog"/>
		<id>http://stackoverflow.com/q/10547033</id>
		<updated>2012-05-15T16:24:01+00:00</updated>
		<content type="html">&lt;p&gt;Take all the distinct bit patterns of length N and arrange them in a cycle such that each
pattern overlaps with its two neighbours in N - 1 bits. Then 
flatten the cycle into a Prolog list.&lt;/p&gt;

&lt;p&gt;Write a predicate &lt;code&gt;pattern(N,L)&lt;/code&gt; that returns a list of bits that comprises all the bit
patterns of length N &gt; 0 following the above rules. Note, there are multiple possible
solutions. You need only produce one.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- pattern(1, L).
L = [0,1]
?- pattern(2, L).
L = [0,0,1,1]
?- pattern(3, L).
L = [0,0,0,1,1,1,0,1]
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>user1388813</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">PROLOG Sum of a list created from facts</title>
		<link href="http://stackoverflow.com/questions/10593666/prolog-sum-of-a-list-created-from-facts"/>
		<id>http://stackoverflow.com/q/10593666</id>
		<updated>2012-05-15T09:58:57+00:00</updated>
		<content type="html">&lt;p&gt;I want to create a list from the facts. And the list should contains only one of the arity in the facts.&lt;/p&gt;

&lt;p&gt;For example : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;%facts
abc(a, b, c).
abc(d, e, f).
abc(g, h, i).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sample : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?-lists(A).
  A = [a, d, g];
  No.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;EDIT : &lt;/p&gt;

&lt;p&gt;Using the suggestion by &lt;code&gt;Vaughn Cato&lt;/code&gt; in the comment, the code become this : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;%facts
abc(a, b, c).
abc(d, e, f).
abc(g, h, i).

lists(A) :-
    findall(findall(X, abc(X, _, _), A).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The list is created, but how to sum up the list &lt;code&gt;A&lt;/code&gt; ?&lt;/p&gt;

&lt;p&gt;If sum of list for input from query, &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sumlist([], 0).
sumlist([X|Y], Sum) :-
    sumlist(Y, Sum1),
    Sum is X + Sum1.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But if want to sum the existing list, how to define the predicate?&lt;/p&gt;</content>
		<author>
			<name>AnonyNewbie</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">sister/brother relationship</title>
		<link href="http://stackoverflow.com/questions/10596829/sister-brother-relationship"/>
		<id>http://stackoverflow.com/q/10596829</id>
		<updated>2012-05-15T09:19:00+00:00</updated>
		<content type="html">&lt;p&gt;I am trying to establish a relationship model in prolog but the sister relationship turns out to be a fail. I am wondering what a good solution would be to this. I am a beginner and this is my first programme, any help is welcome.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;man(adam).
man(peter).
man(paul).
man(carlos).
man(willem).

woman(marry).
woman(eve).
woman(greta).
woman(lisa).


parent(adam,peter). 
parent(eve,peter).
parent(adam,paul).
parent(marry,paul).
parent(adam,willem).
parent(adam, lisa).
parent(eve, willem).
parent(eve, lisa).


parent(greta, adam).
parent(carlos,adam).

father(F,C):-
     man(F),
     parent(F,C).
mother(M,C):-
    woman(M),
    parent(M,C).

grandparrent(P,C):-
   parent(P,K),
   parent(K,C).

sister(x,y):-
   woman(x),
   mother(m,x),
   father(f,x),
   mother(m,y),
   father(f,y).
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>Jorne De Blaere</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">panoz in prolog [closed]</title>
		<link href="http://stackoverflow.com/questions/10581809/panoz-in-prolog"/>
		<id>http://stackoverflow.com/q/10581809</id>
		<updated>2012-05-15T06:11:53+00:00</updated>
		<content type="html">&lt;p&gt;Manhattan has several outlets of the famous Belgian bakery Panoz. During an experiment
with a new kind of chocolate pastry, the old bakery has exploded. A new bakery will be
built, somewhere in Manhattan, and this occasion is used to optimize the distribution of all
the goodies. Clearly Panoz wants the location in Manhattan which minimizes the maximal
(Manhattan) distance from the bakery to any outlet.&lt;/p&gt;

&lt;p&gt;Write a predicate &lt;code&gt;panoz/2&lt;/code&gt; whose queries look like&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- panoz(Outlets,Sol).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where &lt;code&gt;Sol&lt;/code&gt; is the location of the new bakery. The outlet coordinates &lt;code&gt;Outlets&lt;/code&gt; are given as a list of tuples, e.g. &lt;code&gt;[(0, 1), (0, 2), (4, 0), (4, 3)]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is a typical query and its answer:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- panoz([(0, 1), (0, 2), (4, 0), (4, 3)], Sol).
Sol = (2, 2).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course, &lt;code&gt;Sol = (2, 1).&lt;/code&gt; would also have been a good solution.&lt;/p&gt;</content>
		<author>
			<name>Jesica</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Allegrograph Geospatial Prolog Queries</title>
		<link href="http://stackoverflow.com/questions/10588865/allegrograph-geospatial-prolog-queries"/>
		<id>http://stackoverflow.com/q/10588865</id>
		<updated>2012-05-14T20:43:32+00:00</updated>
		<content type="html">&lt;p&gt;I have some triples that represent the locations of several cities.  I want to be able to fire off a Prolog query like &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(select (?x ?y ?dist) 
(q- ?x !exns:geolocation ?locx)
(q- ?y !exns:geolocation ?locy)
(geo-distance ?locx ?locy ?dist))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;but I get this error: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Server returned 400: attempt to call '#:geo-distance/3' which is an undefined function.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I'd like to understand how to use the geospatial reasoning methods like &lt;code&gt;geo-distance&lt;/code&gt; in a Prolog query, because this is currently a mystery to me and I haven't found any good examples for doing this.  &lt;/p&gt;

&lt;p&gt;I am using the Python API, BTW, and in the &lt;a href=&quot;http://www.franz.com/agraph/support/documentation/current/python-tutorial/python-tutorial-40.html#Geospatial%20Search&quot; rel=&quot;nofollow&quot;&gt;Python API tutorial&lt;/a&gt; they use the &lt;code&gt;getStatements&lt;/code&gt; method to retrieve triples within a circle of some radius.  I want to be able to do this kind of thing in a Prolog query.&lt;/p&gt;</content>
		<author>
			<name>John Peter Thompson Garcés</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Even sized list in Prolog</title>
		<link href="http://stackoverflow.com/questions/10580905/even-sized-list-in-prolog"/>
		<id>http://stackoverflow.com/q/10580905</id>
		<updated>2012-05-14T09:57:36+00:00</updated>
		<content type="html">&lt;p&gt;I've been trying to write a predicate which would evaluate the size of a list to be even or not and this has to be done without computing the length of the list or any arithmetic operations. It's supposedly easier than computing the length but I'm having trouble thinking of how to do it without that. I'm guessing a sort of recursive technique but if anyone is able to help it would be great&lt;/p&gt;</content>
		<author>
			<name>Tarek Merachli</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Guess who-like game in Prolog</title>
		<link href="http://stackoverflow.com/questions/10565302/guess-who-like-game-in-prolog"/>
		<id>http://stackoverflow.com/q/10565302</id>
		<updated>2012-05-13T21:49:18+00:00</updated>
		<content type="html">&lt;p&gt;I'm developing a &lt;a href=&quot;http://en.wikipedia.org/wiki/Guess_Who&quot; rel=&quot;nofollow&quot;&gt;Guess Who?&lt;/a&gt; game using Prolog. The mechanics of the game are very easy. A player (in this case, the human) chooses one person among many possible ones, and the other player (the computer) starts asking yes/no questions about some attributes of the person. Eventually, with the given answers, there will only be one possible person.&lt;/p&gt;

&lt;p&gt;So far, I've been able to make a set of rules and predicates so that the computer can guess the person based on the questions that have been asked so far. I have a set of suspects - those are the people that, with the available clues, could fit.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;suspect('Person 1') :- eyes(blue) , age(old) , gender(male).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The predicates for the attributes are defined so that they will be true either if the question regarding that attribute has not been asked yet, or if the question has been asked and the answer matches the attribute of the suspect.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gender(X) :- not(asked_gender) ; value_of(gender, X).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That way, if two suspects share the same eyes and age and different gender, as long as the gender remains unasked, both of them will be plausible suspects.&lt;/p&gt;

&lt;p&gt;However, the hard part now is to automate the process of asking those questions. Basically, I'm looking forward to a solution where Prolog were able to get the possible values for the attributes from the suspects' predicates, instead of listing theme somewhere else. I'm pretty sure there must be a way of doing this, given prolog is able to use the program's code as data itself.&lt;/p&gt;

&lt;p&gt;How could I do that? &lt;/p&gt;</content>
		<author>
			<name>TheOm3ga</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">How to reverse or construct a belief in jason (agentspeak)?</title>
		<link href="http://stackoverflow.com/questions/10445273/how-to-reverse-or-construct-a-belief-in-jason-agentspeak"/>
		<id>http://stackoverflow.com/q/10445273</id>
		<updated>2012-05-13T12:19:46+00:00</updated>
		<content type="html">&lt;p&gt;Jason, Agentspeak, BDI question! &lt;/p&gt;

&lt;p&gt;I would like to do the following:
I have a initial goal with an argument as a belief, and I would like to reverse it, so that the belief's argument becomes the new belief, and the argument becomes the beliefname.&lt;/p&gt;

&lt;p&gt;Something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;//Agent asker in project Test.mas2j
!translate(barks(dog)). //I would like to have the belief: dog(barks)
+!translate(T)&amp;lt;-
    T =.. [A,[B],C];
    .print(&quot;functor: &quot;,A);
    .print(&quot;argument: &quot;,B);
    //.print(&quot;source: &quot;,C);
    +B(A);//&amp;lt;- I want something like this, but it gives a syntax error.
    +B. //&amp;lt;-this works, but it doesn't give the argument to it
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, my question is, hogy to constract beliefs in this way?&lt;/p&gt;</content>
		<author>
			<name>Adamsan</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog transform and separate term (atom) into a list</title>
		<link href="http://stackoverflow.com/questions/10538037/prolog-transform-and-separate-term-atom-into-a-list"/>
		<id>http://stackoverflow.com/q/10538037</id>
		<updated>2012-05-12T20:37:02+00:00</updated>
		<content type="html">&lt;p&gt;I have a term (more accurately an atom) like this: &lt;br /&gt;
&lt;code&gt;name1(value1),name2(value2)&lt;/code&gt; &lt;br /&gt;
and I would like to have instead a &quot;real&quot; list like this: &lt;br /&gt;
&lt;code&gt;[name1(value1), name2(value2)]&lt;/code&gt;&lt;br /&gt;
or separeted terms like this: &lt;br /&gt;
&lt;code&gt;name1(value1)&lt;/code&gt; and &lt;code&gt;name2(value2)&lt;/code&gt; &lt;br /&gt;
any idea on how to do it?&lt;/p&gt;</content>
		<author>
			<name>manullamas</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">prolog passing a function as a variable, how to add arguments?</title>
		<link href="http://stackoverflow.com/questions/10563818/prolog-passing-a-function-as-a-variable-how-to-add-arguments"/>
		<id>http://stackoverflow.com/q/10563818</id>
		<updated>2012-05-12T17:57:37+00:00</updated>
		<content type="html">&lt;p&gt;I have this arbitrary function that I need to call many times with different variables.
btw, this is SWI-Prolog&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;perform(V1,V2,V3,Function,Result):-
    % 
    % do little stuf.
    %
    Function(Arg1,Arg2,Result).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This gives a syntax error.&lt;/p&gt;

&lt;p&gt;But passing a function as a variable without adding arguments works fine as in the following code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;perform(Function):-
    Function.

sayHello:-
    write('hello').

:-perform(sayHello).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So how to add arguments to a variable function?&lt;/p&gt;</content>
		<author>
			<name>user1020753</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">How to join the rectangles in Prolog?</title>
		<link href="http://stackoverflow.com/questions/10427464/how-to-join-the-rectangles-in-prolog"/>
		<id>http://stackoverflow.com/q/10427464</id>
		<updated>2012-05-12T13:28:50+00:00</updated>
		<content type="html">&lt;p&gt;I have a question about how to join the rectangles so that they become another shape?
I have created &lt;code&gt;rectangle/2&lt;/code&gt; facts such as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rectangle(1.14, 2.14).    %rectangle(Length, Width).
rectangle(1.36, 3.34).
rectangle(0.20, 2.35).
rectangle(1.00, 1.30).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But, are these facts correct anyway?&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://postimage.org/image/u7g22p1wv/&quot; rel=&quot;nofollow&quot;&gt;Here&lt;/a&gt; is the image I want to create and &lt;a href=&quot;http://postimage.org/image/uy8s8h4a7/&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; is the image detailing how the rectangles are combined.&lt;/p&gt;

&lt;p&gt;The rectangles should joined using the selected edge.&lt;/p&gt;</content>
		<author>
			<name>AnonyNewbie</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog - How to assert/make a database only once</title>
		<link href="http://stackoverflow.com/questions/10437395/prolog-how-to-assert-make-a-database-only-once"/>
		<id>http://stackoverflow.com/q/10437395</id>
		<updated>2012-05-12T13:15:15+00:00</updated>
		<content type="html">&lt;pre&gt;&lt;code&gt;resultList(UsersQuery):-
    question(X,H),
    write(H),
    myintersection(H,UsersQuery,Match,TotalQuestionKeywords),
    Percent is Match/TotalQuestionKeywords*100,
    write('Question: '),
    write(X),nl,write('Quality: '), write(Percent),write('%'),nl,

    /* please look at this part
    Percent&amp;gt;=50,
    assert(listofQuestions(Percent,Question)),
    write(Percent),write(Question),nl,
    fail.
resultList(_).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I want to populate a fact database named 'listofQuestions'. Everything works fine, but the stuffs that I am asserting stays in the memory. So, if I run my program again, I get the same bunch of facts added to the 'listofQuestions'. &lt;/p&gt;

&lt;p&gt;I only want to have one set of data.&lt;/p&gt;

&lt;p&gt;Thankyou&lt;/p&gt;</content>
		<author>
			<name>HungryCoder</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Making two lists from a given list</title>
		<link href="http://stackoverflow.com/questions/10561697/making-two-lists-from-a-given-list"/>
		<id>http://stackoverflow.com/q/10561697</id>
		<updated>2012-05-12T07:20:27+00:00</updated>
		<content type="html">&lt;p&gt;I am struggling to get my head around Prolog lists. &lt;/p&gt;

&lt;p&gt;Here's my problem: I need to take in a list and two variables and store the odd elements        in list A and the even elements in list B. &lt;/p&gt;

&lt;p&gt;I got this but its not giving the results im looking for  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;store(X, [], []).
store([X,Y|Z],[X|_],[Y|_]):-store(Z,X,Y).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Result should be: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;where ?- store ([a,b,c,1,2,3], A, B).
         A = [b,1,3].
         B = [a,c,2].
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>STee</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">prolog constraint error</title>
		<link href="http://stackoverflow.com/questions/10536484/prolog-constraint-error"/>
		<id>http://stackoverflow.com/q/10536484</id>
		<updated>2012-05-12T00:25:44+00:00</updated>
		<content type="html">&lt;p&gt;I've been working on a SkyScraper sudoku solver, and I think I'm almost there but I'm running into one small issue still. In order to check the 'blocks' of the sudoku board, I use the following code (since the board is not necessarily 9x9):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    bagof(B,
    R^C^(between(1, Sq, R),     %R takes all values from 1 to Sq
     between(1, Sq, C),         %C takes all values from 1 to Sq (double for)
     block(Rows, Sq, R, C, B)),     %Call on block predicate,
    Cells), 



block(InputList, Sq, R,C, B) :-
bagof(V,
   X^Y^(between(1, Sq, X),        %X all values between 1 and Sq
        between(1, Sq, Y),         %Y all values between 1 and Sq
        I is (R-1) * Sq + X,       %Cycling through each 'cell' in each row up to Sq
        J is (C-1) * Sq + Y,       
        cell(InputList, I, J, V)), %Call on cell predicate
    B).      


cell(InputList,R,C, V) :-
nth1(R,InputList,Row),  %Get the rth row (a list)
nth1(C,Row,V).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I was originally using findall in place of bagof, but it came to my attention that it was creating different variables for R/C and X/Y originally, so I switched to bagof and added the C^R^ and X^Y^ that you can see above (I am still not &lt;em&gt;100%&lt;/em&gt; sure I understand the reasoning behind it?). I was expecting this to solve my problem, but so far, no luck. I suppose I could just re-write it using for_each instead of bagof (I believe this would take care of the problem), but I'd also like to know what is causing the trouble? 
I feel confident that this is indeed where the error is occurring, as the answers being returned are correct other than the fact that 'boxes' do not necessarily contain each number exactly once. &lt;/p&gt;

&lt;p&gt;EDIT: After some careful tracing, I've come across the problem (still no solution though). It is not, as I feared above, bagof attempting to constrain new variables as opposed to the ones passed in - it handles that fine. Rather, the problem lies with bagof generating a list of singleton lists, rather than a list of sublists each of length K (for a KxK board). When I switch to findall, this problem goes away, so I believe it has something to do with how bagof is executed. Below are the trace commands, with important sections isolated&lt;/p&gt;

&lt;p&gt;trace with findall - proper 'blocks' returned, but new variables&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;findall(_9966,user:_9973^_9976^(between(1,2,_9973),between(1,2,_9976),block(

[[_7079,_7111,_7143,_7175],[_7270,_7302,_7334,_7366],[_7461,_7493,_7525,_7557],
[_7652,_7684,_7716,_7748]] %input list

,2,_9973,_9976,_9966)),

[[_18106,_18108,_18110,_18112],
[_18096,_18098,_18100,_18102],[_18086,_18088,_18090,_18092],
[_18076,_18078,_18080,_18082]]) ? %output list
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;%trace with bagof - same variables returned, but in singleton list and without 
%changing the order&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; bagof(_9966,user:_9973^_9976^(between(1,2,_9973),between(1,2,_9976),block(

[[_7079,_7111,_7143,_7175],[_7270,_7302,_7334,_7366],[_7461,_7493,_7525,_7557],
[_7652,_7684,_7716,_7748]] %input list

,2,_9973,_9976,_9966)),

[[_7079],[_7111],[_7270],[_7302],
[_7143],[_7175],[_7334],[_7366],[_7461],[_7493],[_7652],[_7684],[_7525],[_7557],[_7716],
[_7748]]) ? %output list
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Second Edit: Problem solved; I forgot to quantify I and J in bagof; whoops! so that line should instead read&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;X^Y^I^J(between(1, Sq, X),        %X all values between 1 and Sq
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and problem solved :) 
Cheers!&lt;/p&gt;</content>
		<author>
			<name>user1257768</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Flowpattern doesn't exist</title>
		<link href="http://stackoverflow.com/questions/10544452/flowpattern-doesnt-exist"/>
		<id>http://stackoverflow.com/q/10544452</id>
		<updated>2012-05-11T02:00:41+00:00</updated>
		<content type="html">&lt;p&gt;I have been working on a code in prolog for a while now and it is near compiling worthy and all my ideas seem to be solid so it should work when it compiles.  It is a program that consults a database file for a list of clauses and then it awaits for a query by the user which it will then pick what information it needs from the sentence and query the database appropriately but there is a block of code that keeps giving me errors complaining that the flowpattern doesn't exist in the standard predicate this may be a silly question but even with all the looking into this I have done i can't find out how to fix this problem if someone could help me out or point me in the right direction that would be greatly appreciated.&lt;/p&gt;

&lt;p&gt;Here is the block of code that gives the error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;loop(STR):- 
           scan(STR,LIST),
           filter(LIST,LISroT1),
           pars(LIST1,LIST2),
           fail.

loop(STR):-    STR &amp;gt;&amp;lt; &quot;&quot;,readquery(L),loop(L).

readquery(QUERY):-nl,nl,write(&quot;Query: &quot;),readln(QUERY).

scan(STR,[TOK|LIST]):-
    fronttoken(STR,SYMB,STR1),!,
    upper_lower(SYMB,TOK),
    scan(STR1,LIST).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the specific line that the compiler complains about is fronttoken(STR,SYMB,STR),!,
any help will be apreaciated thanks!&lt;/p&gt;</content>
		<author>
			<name>user1388126</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Understand lists and recursion in Prolog</title>
		<link href="http://stackoverflow.com/questions/10539326/understand-lists-and-recursion-in-prolog"/>
		<id>http://stackoverflow.com/q/10539326</id>
		<updated>2012-05-10T22:25:39+00:00</updated>
		<content type="html">&lt;p&gt;I'm having a difficult time thinking in Prolog. What is incorrect about this statement:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;numberList([], 0).
numberList([H|T], Limit) :-
    H is Limit,
    numberList(T, Limit - 1).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I would like &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- numberList(X,Limit).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to determine &lt;code&gt;[Limit, Limit-1 ... 1]&lt;/code&gt; as the only solution for a given value for Limit, ie &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- numberList(X, 100).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;would yield &lt;code&gt;X = [100, 99, 98, ..., 1].&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My guess is that there is something pretty wrong with my understanding here for this not to be working. I'm not necessarily asking for a solution to what I am trying to do, I would just like to understand why my first attempt is wrong.&lt;/p&gt;</content>
		<author>
			<name>Matt Esch</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Why do programming competition contestants use C++ and Java?</title>
		<link href="http://stackoverflow.com/questions/3380993/why-do-programming-competition-contestants-use-c-and-java"/>
		<id>http://stackoverflow.com/q/3380993</id>
		<updated>2012-05-10T07:44:47+00:00</updated>
		<content type="html">&lt;p&gt;After competing in and following this year's &lt;a href=&quot;http://code.google.com/codejam/contests.html&quot;&gt;Google Code Jam&lt;/a&gt;  competition, I couldn't help but notice the incredible number of [successful] contestants that used C/C++ and Java. The distribution of languages used throughout the competition can be seen &lt;a href=&quot;http://www.go-hero.net/jam/10/languages/6&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After programming in C/C++ for several years, I recently fell in love with Python for its readable/straightforward nature. More recently, I learned functional languages like OCaml, Scheme, and even logic languages like Prolog. These languages certainly have their merits and, in my opinion, can be applied more easily than C++ and Java for certain situations. For example, Scheme's use of call/cc simplifies backtracking (a tool required to answer several problems) and Prolog's logic specification, although inefficient due to its brute-force nature, can drastically simplify (and even automatically solve) certain problems that are difficult to wrap one's brain around.&lt;/p&gt;

&lt;p&gt;It is clear that a competition contestant should use the tools that are best suited for the challenge. Even x86 assembly is Turing complete - that doesn't justify solving problems with it. In this case, &lt;strong&gt;why are the contestants that use less common languages like Scheme/Lisp, Prolog, and even Python significantly less successful than contestants that use C/C++ and Java?&lt;/strong&gt; Worded differently, &lt;strong&gt;why don't successful contestants use languages that, although may be less mainstream, are arguably better tools for the job?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are several motivations for my question. Most importantly, I would like to become a better programmer - both in the practical aspect and the competition aspect. After being introduced to such beautiful paradigms like functional and logic programming, it is discouraging to see so many people discard them in favor of C/C++ and Java. It even makes me question my admiration for said paradigms, worrying that I cannot be successful as a Lisp/Scheme/Prolog programmer in a programming competition.&lt;/p&gt;</content>
		<author>
			<name>advait</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog: pythagorean triple</title>
		<link href="http://stackoverflow.com/questions/10509258/prolog-pythagorean-triple"/>
		<id>http://stackoverflow.com/q/10509258</id>
		<updated>2012-05-09T21:26:58+00:00</updated>
		<content type="html">&lt;p&gt;I have this code that uses an upper bound variable N that is supposed to terminate for X and Y of the pythagorean triple. However it only freezes when it reaches the upper bound. Wasn't sure how to use the cut to stop the backtracking. Code is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;is_int(0).
is_int(X) :- is_int(Y), X is Y+1.
minus(S,S,0).
minus(S,D1,D2) :- S&amp;gt;0, S1 is S-1, minus(S1,D1,D3), D2 is D3+1.

pythag(X,Y,Z,N) :- int_triple(X,Y,Z,N), Z*Z =:= X*X + Y*Y.

int_triple(X,Y,Z,N) :- is_int(S), minus(S,X,S1), X&amp;gt;0, X&amp;lt;N,
                                  minus(S1,Y,Z), Y&amp;gt;0, Y&amp;lt;N.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Will be called, for example with,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- pythag(X,Y,Z,20).
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>RandellK02</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">factorial (recursion in general) in prolog - why order of terms matters</title>
		<link href="http://stackoverflow.com/questions/10522754/factorial-recursion-in-general-in-prolog-why-order-of-terms-matters"/>
		<id>http://stackoverflow.com/q/10522754</id>
		<updated>2012-05-09T19:34:23+00:00</updated>
		<content type="html">&lt;p&gt;Why this factorial implementation doesn't work:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;factorial(0, B) :- B is 1.
factorial(A, B) :-
                   A &amp;gt; 0,
                   Ax is A-1,
                   B is A*Bx,
                   factorial(Ax, Bx).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And this works:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;factorial2(0, B) :- B is 1.
factorial2(A, B) :-
                   A &amp;gt; 0,
                   Ax is A-1,
                   factorial2(Ax, Bx),
                   B is A*Bx.
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>ajuc</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Find All Relatives with Prolog</title>
		<link href="http://stackoverflow.com/questions/10509474/find-all-relatives-with-prolog"/>
		<id>http://stackoverflow.com/q/10509474</id>
		<updated>2012-05-09T13:25:35+00:00</updated>
		<content type="html">&lt;p&gt;I'm having trouble wrapping my head around how I would return a list of everyone related to a certain person.  So, if I say relatives(A,B), A would be a person and B is a list of all of the people related to that person.  I can write any additional rules needed to assist in doing this.  Here is what I have so far.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;man(joe).
man(tim).
man(milan).
man(matt).
man(eugene).

woman(mary).
woman(emily).
woman(lily).
woman(rosie).
woman(chris).

parent(milan, mary).
parent(tim, milan).
parent(mary, lily).
parent(mary, joe).
parent(mary, matt).
parent(chris, rosie).
parent(eugene, mary).
parent(eugene, chris).

cousins(A, B) :- parent(C, A), parent(D, B), parent(E, C), parent(E, D), not(parent(C, B)), not(parent(D, A)), A \=B.

paternalgrandfather(A, C) :- man(A), man(B), parent(B, C), parent(A, B).

sibling(A, B) :- parent(C, A), parent(C, B), A \= B.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Can someone guide me as to how I would go about doing this?  Thanks.&lt;/p&gt;</content>
		<author>
			<name>MCR</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">What are the pros and cons of using manual list iteration vs recursion through fail</title>
		<link href="http://stackoverflow.com/questions/9744641/what-are-the-pros-and-cons-of-using-manual-list-iteration-vs-recursion-through-f"/>
		<id>http://stackoverflow.com/q/9744641</id>
		<updated>2012-05-09T10:37:25+00:00</updated>
		<content type="html">&lt;p&gt;I come up against this all the time, and I'm never sure which way to attack it. Below are two methods for processing some season facts.&lt;/p&gt;

&lt;p&gt;What I'm trying to work out is whether to use method 1 or 2, and what are the pros and cons of each, especially large amounts of facts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;methodone&lt;/code&gt; seems wasteful since the facts are available, why bother building a list of them (especially a large list). This must have memory implications too if the list is large enough ? And it doesn't take advantage of Prolog's natural backtracking feature. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;methodtwo&lt;/code&gt; takes advantage of backtracking to do the recursion for me, and I would guess would be much more memory efficient, but is it good programming practice generally to do this?  It's arguably uglier to follow, and might there be any other side effects?&lt;/p&gt;

&lt;p&gt;One problem I can see is that each time &lt;code&gt;fail&lt;/code&gt; is called, we lose the ability to pass anything back to the calling predicate, eg. if it was &lt;code&gt;methodtwo(SeasonResults)&lt;/code&gt;, since we continually fail the predicate on purpose. So &lt;code&gt;methodtwo&lt;/code&gt; would need to assert facts to store state.&lt;/p&gt;

&lt;p&gt;Presumably(?) method 2 would be faster as it has no (large) list processing to do?  &lt;/p&gt;

&lt;p&gt;I could imagine that if I had a list, then &lt;code&gt;methodone&lt;/code&gt; would be the way to go.. or is that always true? Might it make sense in any conditions to assert the list to facts using &lt;code&gt;methodone&lt;/code&gt; then process them using method two? Complete madness?&lt;/p&gt;

&lt;p&gt;But then again, I read that asserting facts is a very 'expensive' business, so list handling might be the way to go, even for large lists?&lt;/p&gt;

&lt;p&gt;Any thoughts? Or is it sometimes better to use one and not the other, depending on (what) situation?  eg. for memory optimisation, use method 2, including asserting facts and, for speed use method 1?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;season(spring).
season(summer).
season(autumn).
season(winter).

 % Season handling
showseason(Season) :-
    atom_length(Season, LenSeason),
    write('Season Length is '), write(LenSeason), nl.

% -------------------------------------------------------------
% Method 1 - Findall facts/iterate through the list and process each
%--------------------------------------------------------------
% Iterate manually through a season list
lenseason([]).
lenseason([Season|MoreSeasons]) :-
    showseason(Season),
    lenseason(MoreSeasons).


% Findall to build a list then iterate until all done
methodone :-
    findall(Season, season(Season), AllSeasons),
    lenseason(AllSeasons),
    write('Done').

% -------------------------------------------------------------
% Method 2 - Use fail to force recursion
%--------------------------------------------------------------
methodtwo :-
    % Get one season and show it
    season(Season),
    showseason(Season),

    % Force prolog to backtrack to find another season
    fail.

% No more seasons, we have finished
methodtwo :-
    write('Done').
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>magus</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Optimizing pathfinding in Constraint Logic Programming with Prolog</title>
		<link href="http://stackoverflow.com/questions/8458945/optimizing-pathfinding-in-constraint-logic-programming-with-prolog"/>
		<id>http://stackoverflow.com/q/8458945</id>
		<updated>2012-05-08T22:00:22+00:00</updated>
		<content type="html">&lt;p&gt;I am working on a small prolog application to solve the &lt;a href=&quot;http://www.wpcstylepuzzles.com/2010/05/skyscrapers-in-fences.html&quot;&gt;Skyscrapers and Fences&lt;/a&gt; puzzle.&lt;/p&gt;

&lt;p&gt;An unsolved puzzle:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://i.stack.imgur.com/FEgtN.png&quot; alt=&quot;Skyscrapers in fences puzzle (unsolved)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A solved puzzle:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://i.stack.imgur.com/RQGAG.png&quot; alt=&quot;Skyscrapers in fences puzzle (solved)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When I pass the program already solved puzzles it is quick, almost instantaneous, to validate it for me. When I pass the program really small puzzles (2x2, for example, with modified rules, of course), it is also quite fast to find a solution.&lt;/p&gt;

&lt;p&gt;The problem is on computing puzzles with the &quot;native&quot; size of 6x6. I've left it running for 5 or so hours before aborting it. Way too much time.&lt;/p&gt;

&lt;p&gt;I've found that the part that takes the longest is the &quot;fences&quot; one, not the &quot;skyscrapers&quot;. Running &quot;skyscrapers&quot; separately results in a fast solution.&lt;/p&gt;

&lt;p&gt;Here's my algorithm for fences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vertices are represented by numbers, 0 means the path doesn't pass through that particular vertex, &gt; 1 represents that vertex's order in the path.&lt;/li&gt;
&lt;li&gt;Constrain each cell to have the appropriate amount of lines surrounding it.
&lt;ul&gt;
&lt;li&gt;That means that two vertexes are connected if they have sequential numbers, e.g., 1 -&gt; 2, 2 -&gt; 1, 1 -&gt; &lt;code&gt;Max&lt;/code&gt;, &lt;code&gt;Max&lt;/code&gt; -&gt; 1 (&lt;code&gt;Max&lt;/code&gt; is the number for the last vertex in the path. computed via &lt;code&gt;maximum/2&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Make sure each non-zero vertex has at least two neighboring vertices with sequential numbers&lt;/li&gt;
&lt;li&gt;Constrain &lt;code&gt;Max&lt;/code&gt; to be equal to &lt;code&gt;(BoardWidth + 1)^2 - NumberOfZeros&lt;/code&gt; (&lt;code&gt;BoardWidth+1&lt;/code&gt; is the number of vertices along the edge and &lt;code&gt;NumberOfZeros&lt;/code&gt; is computed via &lt;code&gt;count/4&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;nvalue(Vertices, Max + 1)&lt;/code&gt; to make sure the number of distinct values in &lt;code&gt;Vertices&lt;/code&gt; is &lt;code&gt;Max&lt;/code&gt; (i.e. the number of vertices in the path) plus &lt;code&gt;1&lt;/code&gt; (zero values)&lt;/li&gt;
&lt;li&gt;Find the first cell containing a &lt;code&gt;3&lt;/code&gt; and force the path to begin and end there, for efficiency purposes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What can I do to increase efficiency? Code is included below for reference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;skyscrapersinfences.pro&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:-use_module(library(clpfd)).
:-use_module(library(lists)).

:-ensure_loaded('utils.pro').
:-ensure_loaded('s1.pro').

print_row([]).

print_row([Head|Tail]) :-
    write(Head), write(' '),
    print_row(Tail).

print_board(Board, BoardWidth) :-
    print_board(Board, BoardWidth, 0).

print_board(_, BoardWidth, BoardWidth).

print_board(Board, BoardWidth, Index) :-
    make_segment(Board, BoardWidth, Index, row, Row),
    print_row(Row), nl,
    NewIndex is Index + 1,
    print_board(Board, BoardWidth, NewIndex).

print_boards([], _).
print_boards([Head|Tail], BoardWidth) :-
    print_board(Head, BoardWidth), nl,
    print_boards(Tail, BoardWidth).

get_board_element(Board, BoardWidth, X, Y, Element) :-
    Index is BoardWidth*Y + X,
    get_element_at(Board, Index, Element).

make_column([], _, _, []).

make_column(Board, BoardWidth, Index, Segment) :-
    get_element_at(Board, Index, Element),
    munch(Board, BoardWidth, MunchedBoard),
    make_column(MunchedBoard, BoardWidth, Index, ColumnTail),
    append([Element], ColumnTail, Segment).

make_segment(Board, BoardWidth, Index, row, Segment) :-
    NIrrelevantElements is BoardWidth*Index,
    munch(Board, NIrrelevantElements, MunchedBoard),
    select_n_elements(MunchedBoard, BoardWidth, Segment).

make_segment(Board, BoardWidth, Index, column, Segment) :-
    make_column(Board, BoardWidth, Index, Segment).

verify_segment(_, 0).
verify_segment(Segment, Value) :-
    verify_segment(Segment, Value, 0).

verify_segment([], 0, _).
verify_segment([Head|Tail], Value, Max) :-
    Head #&amp;gt; Max #&amp;lt;=&amp;gt; B, 
    Value #= M+B,
    maximum(NewMax, [Head, Max]),
    verify_segment(Tail, M, NewMax).

exactly(_, [], 0).
exactly(X, [Y|L], N) :-
    X #= Y #&amp;lt;=&amp;gt; B,
    N #= M  +B,
    exactly(X, L, M).

constrain_numbers(Vars) :-
    exactly(3, Vars, 1),
    exactly(2, Vars, 1),
    exactly(1, Vars, 1).

iteration_values(BoardWidth, Index, row, 0, column) :-
    Index is BoardWidth - 1.

iteration_values(BoardWidth, Index, Type, NewIndex, Type) :-
    \+((Type = row, Index is BoardWidth - 1)),
    NewIndex is Index + 1.

solve_skyscrapers(Board, BoardWidth) :-
    solve_skyscrapers(Board, BoardWidth, 0, row).

solve_skyscrapers(_, BoardWidth, BoardWidth, column).

solve_skyscrapers(Board, BoardWidth, Index, Type) :-
    make_segment(Board, BoardWidth, Index, Type, Segment),

    domain(Segment, 0, 3),
    constrain_numbers(Segment),

    observer(Type, Index, forward, ForwardObserver),
    verify_segment(Segment, ForwardObserver),

    observer(Type, Index, reverse, ReverseObserver),
    reverse(Segment, ReversedSegment),
    verify_segment(ReversedSegment, ReverseObserver),

    iteration_values(BoardWidth, Index, Type, NewIndex, NewType),
    solve_skyscrapers(Board, BoardWidth, NewIndex, NewType).

build_vertex_list(_, Vertices, BoardWidth, X, Y, List) :-
    V1X is X, V1Y is Y, V1Index is V1X + V1Y*(BoardWidth+1),
    V2X is X+1, V2Y is Y, V2Index is V2X + V2Y*(BoardWidth+1),
    V3X is X+1, V3Y is Y+1, V3Index is V3X + V3Y*(BoardWidth+1),
    V4X is X, V4Y is Y+1, V4Index is V4X + V4Y*(BoardWidth+1),
    get_element_at(Vertices, V1Index, V1),
    get_element_at(Vertices, V2Index, V2),
    get_element_at(Vertices, V3Index, V3),
    get_element_at(Vertices, V4Index, V4),
    List = [V1, V2, V3, V4].

build_neighbors_list(Vertices, VertexWidth, X, Y, [NorthMask, EastMask, SouthMask, WestMask], [NorthNeighbor, EastNeighbor, SouthNeighbor, WestNeighbor]) :-
    NorthY is Y - 1,
    EastX is X + 1,
    SouthY is Y + 1,
    WestX is X - 1,
    NorthNeighborIndex is (NorthY)*VertexWidth + X,
    EastNeighborIndex is Y*VertexWidth + EastX,
    SouthNeighborIndex is (SouthY)*VertexWidth + X,
    WestNeighborIndex is Y*VertexWidth + WestX,
    (NorthY &amp;gt;= 0, get_element_at(Vertices, NorthNeighborIndex, NorthNeighbor) -&amp;gt; NorthMask = 1 ; NorthMask = 0),
    (EastX &amp;lt; VertexWidth, get_element_at(Vertices, EastNeighborIndex, EastNeighbor) -&amp;gt; EastMask = 1 ; EastMask = 0),
    (SouthY &amp;lt; VertexWidth, get_element_at(Vertices, SouthNeighborIndex, SouthNeighbor) -&amp;gt; SouthMask = 1 ; SouthMask = 0),
    (WestX &amp;gt;= 0, get_element_at(Vertices, WestNeighborIndex, WestNeighbor) -&amp;gt; WestMask = 1 ; WestMask = 0).

solve_path(_, VertexWidth, 0, VertexWidth) :-
    write('end'),nl.

solve_path(Vertices, VertexWidth, VertexWidth, Y) :-
    write('switch row'),nl,
    Y \= VertexWidth,
    NewY is Y + 1,
    solve_path(Vertices, VertexWidth, 0, NewY).

solve_path(Vertices, VertexWidth, X, Y) :-
    X &amp;gt;= 0, X &amp;lt; VertexWidth, Y &amp;gt;= 0, Y &amp;lt; VertexWidth,
    write('Path: '), nl,
    write('Vertex width: '), write(VertexWidth), nl,
    write('X: '), write(X), write(' Y: '), write(Y), nl,
    VertexIndex is X + Y*VertexWidth,
    write('1'),nl,
    get_element_at(Vertices, VertexIndex, Vertex),
    write('2'),nl,
    build_neighbors_list(Vertices, VertexWidth, X, Y, [NorthMask, EastMask, SouthMask, WestMask], [NorthNeighbor, EastNeighbor, SouthNeighbor, WestNeighbor]),
    L1 = [NorthMask, EastMask, SouthMask, WestMask],
    L2 = [NorthNeighbor, EastNeighbor, SouthNeighbor, WestNeighbor],
    write(L1),nl,
    write(L2),nl,
    write('3'),nl,
    maximum(Max, Vertices),
    write('4'),nl,
    write('Max: '), write(Max),nl,
    write('Vertex: '), write(Vertex),nl,
    (Vertex #&amp;gt; 1 #/\ Vertex #\= Max) #=&amp;gt; (
                        ((NorthMask #&amp;gt; 0 #/\ NorthNeighbor #&amp;gt; 0) #/\ (NorthNeighbor #= Vertex - 1)) #\
                        ((EastMask #&amp;gt; 0 #/\ EastNeighbor #&amp;gt; 0) #/\ (EastNeighbor #= Vertex - 1)) #\
                        ((SouthMask #&amp;gt; 0 #/\ SouthNeighbor #&amp;gt; 0) #/\ (SouthNeighbor #= Vertex - 1)) #\
                        ((WestMask #&amp;gt; 0 #/\ WestNeighbor #&amp;gt; 0) #/\ (WestNeighbor #= Vertex - 1))
                    ) #/\ (
                        ((NorthMask #&amp;gt; 0 #/\ NorthNeighbor #&amp;gt; 0) #/\ (NorthNeighbor #= Vertex + 1)) #\
                        ((EastMask #&amp;gt; 0 #/\ EastNeighbor #&amp;gt; 0) #/\ (EastNeighbor #= Vertex + 1)) #\
                        ((SouthMask #&amp;gt; 0 #/\ SouthNeighbor #&amp;gt; 0) #/\ (SouthNeighbor #= Vertex + 1)) #\
                        ((WestMask #&amp;gt; 0 #/\ WestNeighbor #&amp;gt; 0) #/\ (WestNeighbor #= Vertex + 1))
                    ),
    write('5'),nl,
    Vertex #= 1 #=&amp;gt; (
                        ((NorthMask #&amp;gt; 0 #/\ NorthNeighbor #&amp;gt; 0) #/\ (NorthNeighbor #= Max)) #\
                        ((EastMask #&amp;gt; 0 #/\ EastNeighbor #&amp;gt; 0) #/\ (EastNeighbor #= Max)) #\
                        ((SouthMask #&amp;gt; 0 #/\ SouthNeighbor #&amp;gt; 0) #/\ (SouthNeighbor #= Max)) #\
                        ((WestMask #&amp;gt; 0 #/\ WestNeighbor #&amp;gt; 0) #/\ (WestNeighbor #= Max))
                    ) #/\ (
                        ((NorthMask #&amp;gt; 0 #/\ NorthNeighbor #&amp;gt; 0) #/\ (NorthNeighbor #= 2)) #\
                        ((EastMask #&amp;gt; 0 #/\ EastNeighbor #&amp;gt; 0) #/\ (EastNeighbor #= 2)) #\
                        ((SouthMask #&amp;gt; 0 #/\ SouthNeighbor #&amp;gt; 0) #/\ (SouthNeighbor #= 2)) #\
                        ((WestMask #&amp;gt; 0 #/\ WestNeighbor #&amp;gt; 0) #/\ (WestNeighbor #= 2))
                    ),

    write('6'),nl,
    Vertex #= Max #=&amp;gt; (
                        ((NorthMask #&amp;gt; 0 #/\ NorthNeighbor #&amp;gt; 0) #/\ (NorthNeighbor #= 1)) #\
                        ((EastMask #&amp;gt; 0 #/\ EastNeighbor #&amp;gt; 0) #/\ (EastNeighbor #= 1)) #\
                        ((SouthMask #&amp;gt; 0 #/\ SouthNeighbor #&amp;gt; 0) #/\ (SouthNeighbor #= 1)) #\
                        ((WestMask #&amp;gt; 0 #/\ WestNeighbor #&amp;gt; 0) #/\ (WestNeighbor #= 1))
                    ) #/\ (
                        ((NorthMask #&amp;gt; 0 #/\ NorthNeighbor #&amp;gt; 0) #/\ (NorthNeighbor #= Max - 1)) #\
                        ((EastMask #&amp;gt; 0 #/\ EastNeighbor #&amp;gt; 0) #/\ (EastNeighbor #= Max - 1)) #\
                        ((SouthMask #&amp;gt; 0 #/\ SouthNeighbor   #&amp;gt; 0) #/\ (SouthNeighbor #= Max - 1)) #\
                        ((WestMask #&amp;gt; 0 #/\ WestNeighbor #&amp;gt; 0) #/\ (WestNeighbor #= Max - 1))
                    ),

    write('7'),nl,
    NewX is X + 1,
    solve_path(Vertices, VertexWidth, NewX, Y).

solve_fences(Board, Vertices, BoardWidth) :-
    VertexWidth is BoardWidth + 1,
    write('- Solving vertices'),nl,
    solve_vertices(Board, Vertices, BoardWidth, 0, 0),
    write('- Solving path'),nl,
    solve_path(Vertices, VertexWidth, 0, 0).

solve_vertices(_, _, BoardWidth, 0, BoardWidth).

solve_vertices(Board, Vertices, BoardWidth, BoardWidth, Y) :-
    Y \= BoardWidth,
    NewY is Y + 1,
    solve_vertices(Board, Vertices, BoardWidth, 0, NewY).

solve_vertices(Board, Vertices, BoardWidth, X, Y) :-
    X &amp;gt;= 0, X &amp;lt; BoardWidth, Y &amp;gt;= 0, Y &amp;lt; BoardWidth,
    write('process'),nl,
    write('X: '), write(X), write(' Y: '), write(Y), nl,
    build_vertex_list(Board, Vertices, BoardWidth, X, Y, [V1, V2, V3, V4]),
    write('1'),nl,
    get_board_element(Board, BoardWidth, X, Y, Element),
    write('2'),nl,
    maximum(Max, Vertices),
    (V1 #&amp;gt; 0 #/\ V2 #&amp;gt; 0 #/\ 
        (
            (V1 + 1 #= V2) #\ 
            (V1 - 1 #= V2) #\ 
            (V1 #= Max #/\ V2 #= 1) #\
            (V1 #= 1 #/\ V2 #= Max) 
        ) 
    ) #&amp;lt;=&amp;gt; B1,
    (V2 #&amp;gt; 0 #/\ V3 #&amp;gt; 0 #/\ 
        (
            (V2 + 1 #= V3) #\ 
            (V2 - 1 #= V3) #\ 
            (V2 #= Max #/\ V3 #= 1) #\
            (V2 #= 1 #/\ V3 #= Max) 
        ) 
    ) #&amp;lt;=&amp;gt; B2,
    (V3 #&amp;gt; 0 #/\ V4 #&amp;gt; 0 #/\ 
        (
            (V3 + 1 #= V4) #\ 
            (V3 - 1 #= V4) #\ 
            (V3 #= Max #/\ V4 #= 1) #\
            (V3 #= 1 #/\ V4 #= Max) 
        ) 
    ) #&amp;lt;=&amp;gt; B3,
    (V4 #&amp;gt; 0 #/\ V1 #&amp;gt; 0 #/\ 
        (
            (V4 + 1 #= V1) #\ 
            (V4 - 1 #= V1) #\ 
            (V4 #= Max #/\ V1 #= 1) #\
            (V4 #= 1 #/\ V1 #= Max) 
        ) 
    ) #&amp;lt;=&amp;gt; B4,
    write('3'),nl,
    sum([B1, B2, B3, B4], #= , C),
    write('4'),nl,
    Element #&amp;gt; 0 #=&amp;gt; C #= Element,
    write('5'),nl,
    NewX is X + 1,
    solve_vertices(Board, Vertices, BoardWidth, NewX, Y).

sel_next_variable_for_path(Vars,Sel,Rest) :-
    % write(Vars), nl,
    findall(Idx-Cost, (nth1(Idx, Vars,V), fd_set(V,S), fdset_size(S,Size), fdset_min(S,Min),  var_cost(Min,Size, Cost)), L), 
    min_member(comp, BestIdx-_MinCost, L),
    nth1(BestIdx, Vars, Sel, Rest),!.

var_cost(0, _, 1000000) :- !.
var_cost(_, 1, 1000000) :- !.
var_cost(X, _, X).

%build_vertex_list(_, Vertices, BoardWidth, X, Y, List)

constrain_starting_and_ending_vertices(Vertices, [V1,V2,V3,V4]) :-
    maximum(Max, Vertices),
    (V1 #= 1 #/\        V2 #= Max #/\       V3 #= Max - 1 #/\   V4 #= 2         ) #\
    (V1 #= Max #/\      V2 #= 1 #/\         V3 #= 2 #/\         V4 #= Max - 1   ) #\
    (V1 #= Max - 1 #/\  V2 #= Max #/\       V3 #= 1 #/\         V4 #= 2         ) #\
    (V1 #= 2 #/\        V2 #= 1 #/\         V3 #= Max #/\       V4 #= Max - 1   ) #\
    (V1 #= 1 #/\        V2 #= 2 #/\         V3 #= Max - 1 #/\   V4 #= Max       ) #\
    (V1 #= Max #/\      V2 #= Max - 1 #/\   V3 #= 2 #/\         V4 #= 1         ) #\
    (V1 #= Max - 1 #/\  V2 #= 2 #/\         V3 #= 1 #/\         V4 #= Max       ) #\
    (V1 #= 2 #/\        V2 #= Max - 1 #/\   V3 #= Max #/\       V4 #= 1         ).

set_starting_and_ending_vertices(Board, Vertices, BoardWidth) :-
    set_starting_and_ending_vertices(Board, Vertices, BoardWidth, 0, 0).

set_starting_and_ending_vertices(Board, Vertices, BoardWidth, BoardWidth, Y) :-
    Y \= BoardWidth,
    NewY is Y + 1,
    solve_path(Board, Vertices, BoardWidth, 0, NewY).

set_starting_and_ending_vertices(Board, Vertices, BoardWidth, X, Y) :-
    X &amp;gt;= 0, X &amp;lt; BoardWidth, Y &amp;gt;= 0, Y &amp;lt; BoardWidth,
    build_vertex_list(_, Vertices, BoardWidth, X, Y, List),
    get_board_element(Board, BoardWidth, X, Y, Element),
    (Element = 3 -&amp;gt; 
        constrain_starting_and_ending_vertices(Vertices, List) 
        ; 
            NewX is X + 1,
        set_starting_and_ending_vertices(Board, Vertices, BoardWidth, NewX, Y)).

solve(Board, Vertices, BoardWidth) :-
    write('Skyscrapers'), nl,
    solve_skyscrapers(Board, BoardWidth),
    write('Labeling'), nl,
    labeling([ff], Board), !, 
    write('Setting domain'), nl,
    NVertices is (BoardWidth+1)*(BoardWidth+1),
    domain(Vertices, 0, NVertices),
    write('Starting and ending vertices'), nl,
    set_starting_and_ending_vertices(Board, Vertices, BoardWidth),
    write('Setting maximum'), nl,
    maximum(Max, Vertices),
    write('1'),nl,
    Max #&amp;gt; BoardWidth + 1,
    write('2'),nl,
    Max #&amp;lt; NVertices,
    count(0, Vertices, #=, NZeros),
    Max #= NVertices - NZeros,
    write('3'),nl,
    write('Calling nvalue'), nl,
    ValueCount #= Max + 1,
    nvalue(ValueCount, Vertices),
    write('Solving fences'), nl,
    solve_fences(Board, Vertices, BoardWidth),
    write('Labeling'), nl,
    labeling([ff], Vertices).

main :-
    board(Board),
    board_width(BoardWidth),
    vertices(Vertices),

    solve(Board, Vertices, BoardWidth),

    %findall(Board,
    %   labeling([ff], Board),
    %   Boards
    %),

    %append(Board, Vertices, Final),

    write('done.'),nl,
    print_board(Board, 6), nl,
    print_board(Vertices, 7).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;utils.pro&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;get_element_at([Head|_], 0, Head).

get_element_at([_|Tail], Index, Element) :-
  Index \= 0,
  NewIndex is Index - 1,
  get_element_at(Tail, NewIndex, Element).

reverse([], []).

reverse([Head|Tail], Inv) :-
  reverse(Tail, Aux),
  append(Aux, [Head], Inv).

munch(List, 0, List).

munch([_|Tail], Count, FinalList) :-
    Count &amp;gt; 0,
    NewCount is Count - 1,
    munch(Tail, NewCount, FinalList).

select_n_elements(_, 0, []).

select_n_elements([Head|Tail], Count, FinalList) :-
    Count &amp;gt; 0,
    NewCount is Count - 1,
    select_n_elements(Tail, NewCount, Result),
    append([Head], Result, FinalList).

generate_list(Element, NElements, [Element|Result]) :-
  NElements &amp;gt; 0,
  NewNElements is NElements - 1,
  generate_list(Element, NewNElements, Result).

generate_list(_, 0, []).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;s1.pro&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% Skyscrapers and Fences puzzle S1

board_width(6).

%observer(Type, Index, Orientation, Observer),
observer(row, 0, forward, 2).
observer(row, 1, forward, 2).
observer(row, 2, forward, 2).
observer(row, 3, forward, 1).
observer(row, 4, forward, 2).
observer(row, 5, forward, 1).

observer(row, 0, reverse, 1).
observer(row, 1, reverse, 1).
observer(row, 2, reverse, 2).
observer(row, 3, reverse, 3).
observer(row, 4, reverse, 2).
observer(row, 5, reverse, 2).

observer(column, 0, forward, 2).
observer(column, 1, forward, 3).
observer(column, 2, forward, 0).
observer(column, 3, forward, 2).
observer(column, 4, forward, 2).
observer(column, 5, forward, 1).

observer(column, 0, reverse, 1).
observer(column, 1, reverse, 1).
observer(column, 2, reverse, 2).
observer(column, 3, reverse, 2).
observer(column, 4, reverse, 2).
observer(column, 5, reverse, 2).

board(
    [
        _, _, 2, _, _, _,
        _, _, _, _, _, _,
        _, 2, _, _, _, _,
        _, _, _, 2, _, _,
        _, _, _, _, _, _,
        _, _, _, _, _, _
    ]
).

vertices(
    [
        _, _, _, _, _, _, _,
        _, _, _, _, _, _, _,
        _, _, _, _, _, _, _,
        _, _, _, _, _, _, _,
        _, _, _, _, _, _, _,
        _, _, _, _, _, _, _,
        _, _, _, _, _, _, _
    ]
).
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>Francisco P.</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Tree postorder traversal in Prolog</title>
		<link href="http://stackoverflow.com/questions/10504656/tree-postorder-traversal-in-prolog"/>
		<id>http://stackoverflow.com/q/10504656</id>
		<updated>2012-05-08T19:24:03+00:00</updated>
		<content type="html">&lt;p&gt;Tree traversal refers to the process of visiting each node in a tree data structure in a systematic way. The &lt;code&gt;postorder&lt;/code&gt; traversal in the following image&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/File%3aSorted_binary_tree.svg&quot; rel=&quot;nofollow&quot;&gt;Sorted_binary_tree&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;returns &lt;code&gt;A, C, E, D, B, H, I, G, F (left, right, root)&lt;/code&gt;. The Prolog code for &lt;code&gt;PREORDER&lt;/code&gt; traversal is&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;preorder(tree(X,L,R),Xs) :-
    preorder(L,Ls),
    preorder(R,Rs),
    append([X|Ls],Rs,Xs).

preorder(void,[]).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I would like to modify the above code to implement postorder traversal. Any suggestions?&lt;/p&gt;</content>
		<author>
			<name>Mark</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">What's the -&amp;gt; operator in Prolog and how can I use it?</title>
		<link href="http://stackoverflow.com/questions/1775651/whats-the-operator-in-prolog-and-how-can-i-use-it"/>
		<id>http://stackoverflow.com/q/1775651</id>
		<updated>2012-05-08T19:05:45+00:00</updated>
		<content type="html">&lt;p&gt;I've read about it in a book but it wasn't explained at all. I also never saw it in a program. Is part of Prolog syntax? What's it for? Do you use it?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</content>
		<author>
			<name>Juanjo Conti</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Lists with Prolog</title>
		<link href="http://stackoverflow.com/questions/10502868/lists-with-prolog"/>
		<id>http://stackoverflow.com/q/10502868</id>
		<updated>2012-05-08T17:24:57+00:00</updated>
		<content type="html">&lt;p&gt;I'm learning prolog and having some trouble with lists.  I want to return a list of classes that are prerequisites for a specified class.  Here is what I have so far...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;prereq(262, 221).
prereq(271, 262).
prereq(331, 271).

prerequisites(A, B) :- not(prereq(A, C)).
prerequisites(A, [C|B]) :- prereq(A, C), prerequisites(C, B).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It works, but appends junk onto the end.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- prerequisites(331, A).
A = [271, 262, 221|_G327] ;
false.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Can someone show me what I'm doing wrong?  Thanks!&lt;/p&gt;</content>
		<author>
			<name>MCR</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">OWL reasoning in Prolog query from AllegroGraph Python API</title>
		<link href="http://stackoverflow.com/questions/10489540/owl-reasoning-in-prolog-query-from-allegrograph-python-api"/>
		<id>http://stackoverflow.com/q/10489540</id>
		<updated>2012-05-08T17:22:36+00:00</updated>
		<content type="html">&lt;p&gt;I noticed that in the AllegroGraph Python API tutorial &lt;a href=&quot;http://www.franz.com/agraph/support/documentation/3.2/python-tutorial.html#RDFS++%20Inference&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;, whenever they want to use OWL reasoning they use the &lt;code&gt;conn.getStatements&lt;/code&gt; method instead of issuing a Prolog or SPARQL query.  Is it possible to get triples inferred from the OWL reasoner by issuing a Prolog or SPARQL query instead of using the &lt;code&gt;conn.getStatements&lt;/code&gt; method?  I tried a Prolog query:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(select (?x ?y) (q ?x !ex:owned-by ?y))&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;where I had defined owned-by as &lt;code&gt;owl:inverseOf ex:owns&lt;/code&gt; and had the triple &lt;code&gt;ex:someone ex:owns ex:something&lt;/code&gt; in my store, and I got no results.  I do get results from using &lt;code&gt;conn.getStatements&lt;/code&gt;, so am I missing something essential in the Prolog query?&lt;/p&gt;</content>
		<author>
			<name>John Peter Thompson Garcés</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Calculating Time Difference in Prolog</title>
		<link href="http://stackoverflow.com/questions/10486701/calculating-time-difference-in-prolog"/>
		<id>http://stackoverflow.com/q/10486701</id>
		<updated>2012-05-08T03:33:15+00:00</updated>
		<content type="html">&lt;p&gt;I'm having some trouble writing a relatively simple predicate in Prolog. This predicate is supposed to receive two arguments in the format Hours:Minutes, calculate the difference between the two and check if that value is greater or equal to 40 minutes.&lt;/p&gt;

&lt;p&gt;Here's what I have so far:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;time(Time1, Time2):- 
    X:Y =:= Time1, A:B =:= Time2, calculate_time(X, Y, A, B).

calculate_time(X, Y, A, B):-
    Y - X =:= 0,
    B - A &amp;gt;= 40, !.
calculate_time(X, Y, A, B):-
    Y - X &amp;gt; 0.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This, as you can imagine, is giving an error, namely:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- time(10:00, 10:55).
 ERROR at  clause 1 of user:time/2 !!
 INSTANTIATION ERROR- in arithmetic: expected bound value
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, as far as I can understand, he thinks that he's been given four arguments. Why is he reacting this way? Also, at the beginning of the file, I have the following commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:-op(500,xfy,:).
:-op(600,xfy,/).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This predicate is supposed to be a part of a larger program, so these two lines need to stay in the file. I'm not using any module and I'm using YAP.&lt;/p&gt;

&lt;p&gt;Any help would be appreciated!&lt;/p&gt;</content>
		<author>
			<name>Lopson</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">How do I turn of Swi-Prolog flags?</title>
		<link href="http://stackoverflow.com/questions/10490598/how-do-i-turn-of-swi-prolog-flags"/>
		<id>http://stackoverflow.com/q/10490598</id>
		<updated>2012-05-08T00:11:46+00:00</updated>
		<content type="html">&lt;p&gt;I'm not sure if flags is the appropriate term, but is there anyway to configure a swi-prolog program to not output true or false on the completion of a query, and instead, simply printing out another statement determined in the program?&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;</content>
		<author>
			<name>jldavis76</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Regarding two implementations of min_of_list in prolog</title>
		<link href="http://stackoverflow.com/questions/10489278/regarding-two-implementations-of-min-of-list-in-prolog"/>
		<id>http://stackoverflow.com/q/10489278</id>
		<updated>2012-05-07T22:44:01+00:00</updated>
		<content type="html">&lt;p&gt;Can someone explain clearly why this implementation (from SO 3965054) of min_of_list works in prolog:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% via: http://stackoverflow.com/questions/3965054/prolog-find-minimum-in-a-list
min_of_list_1( [H], H).
min_of_list_1([H,K|T],M) :- H =&amp;lt; K, min_of_list_1([H|T],M). 
min_of_list_1([H,K|T],M) :- H &amp;gt; K,  min_of_list_1([K|T],M).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;while this implementation generates an incorrect output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;min_of_list_2( [H], H).
min_of_list_2( [H| T], X) :- compare(&amp;lt;, X, H), min_of_list_2(T, X).
min_of_list_2( [H| T], H) :- compare(&amp;gt;, X, H), min_of_list_2(T, X).
min_of_list_2( [H| T], H) :- compare(=, X, H), min_of_list_2(T, H).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Epilogue.  This works.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;min_of_list_3( [H], H).
min_of_list_3( [H| T], X) :- min_of_list_3(T, X), compare(&amp;lt;, X, H).
min_of_list_3( [H| T], H) :- min_of_list_3(T, X), compare(&amp;gt;, X, H).
min_of_list_3( [H| T], H) :- min_of_list_3(T, X), compare(=, X, H).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;?&lt;/p&gt;

&lt;p&gt;The behavior I get is that min_of_list_2 returns the last element in the list.
Thanks.&lt;/p&gt;</content>
		<author>
			<name>BlessedKey</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog, find minimum in a list</title>
		<link href="http://stackoverflow.com/questions/3965054/prolog-find-minimum-in-a-list"/>
		<id>http://stackoverflow.com/q/3965054</id>
		<updated>2012-05-06T19:07:30+00:00</updated>
		<content type="html">&lt;p&gt;in short: How to find min value in a list? (thanks for the advise kaarel)&lt;/p&gt;

&lt;p&gt;long story: &lt;/p&gt;

&lt;p&gt;I have created a weighted graph in amzi prolog and given 2 nodes, I am able to retrieve a list of paths. However, I need to find the minimum value in this path but am unable to traverse the list to do this. May I please seek your advise on how to determine the minimum value in the list?&lt;/p&gt;

&lt;p&gt;my code currently looks like this:&lt;/p&gt;

&lt;p&gt;arc(1,2).
arc(2,3).
arc(3,4).
arc(3,5).
arc(3,6).
arc(2,5).
arc(5,6).
arc(2,6).
path(X,Z,A) :- 
 (arc(X,Y),path(Y,Z,A1),A is A1+1;arc(X,Z), A is 1).&lt;/p&gt;

&lt;p&gt;thus, ' keying findall(Z,path(2,6,Z),L).' in listener allows me to attain a list [3,2,2,1].
I need to retrieve the minimum value from here and multiply it with an amount. Can someone please advise on how to retrieve the minimum value? thanks!&lt;/p&gt;</content>
		<author>
			<name>Roy</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog list difference routine</title>
		<link href="http://stackoverflow.com/questions/1523172/prolog-list-difference-routine"/>
		<id>http://stackoverflow.com/q/1523172</id>
		<updated>2012-05-06T13:09:59+00:00</updated>
		<content type="html">&lt;p&gt;I am trying to implement a list difference routine in prolog.
For some reason the following fails:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;difference(Xs,Ys,D) :- difference(Xs,Ys,[],D).
difference([],_,A,D) :- D is A, !.
difference([X|Xs],Ys,A,D) :-
  not(member(X,Ys)),
  A1 is [X|A],
  difference(Xs,Ys,A1,D).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When trying:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?- difference([1,2],[],D).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I get this error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ERROR: '.'/2: Type error: `[]' expected, found `1' (&quot;x&quot; must hold one character)
^  Exception: (10) _L161 is [2|1] ?
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>Ramin</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">How can I find the common station between two points of a map in Prolog?</title>
		<link href="http://stackoverflow.com/questions/10459601/how-can-i-find-the-common-station-between-two-points-of-a-map-in-prolog"/>
		<id>http://stackoverflow.com/q/10459601</id>
		<updated>2012-05-06T05:36:21+00:00</updated>
		<content type="html">&lt;p&gt;There is the situation: I have little part of the London underground declared on specific lines in Prolog.  I have 3 lines with several stations, and they all have common points with each other.
&lt;img src=&quot;http://i.stack.imgur.com/444He.jpg&quot; alt=&quot;The map of the underground&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I have facts for the stations, where the arguments are the stations next to one another and the line what they are on. There is the full list of the stations on the map:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;neighbour(south_kensington,victoria,green).
neighbour(victoria,westminster,green).
neighbour(westminster,embankment,green).
neighbour(embankment,blackfriars,green).
neighbour(vauxhall,victoria,blue).
neighbour(victoria,green_park,blue).
neighbour(green_park,oxford_circus,blue).
neighbour(oxford_circus,warren_street,blue).
neighbour(warren_street,euston,blue).
neighbour(warren_street,tottenham_court_road,black).
neighbour(tottenham_court_road,leichester_square,black).
neighbour(leichester_square,charing_cross,black).
neighbour(charing_cross,embankbent,black).
neighbour(embankment,waterloo,black).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The problem is: I want to go from A to B (they are on different lines) and Mr Prolog should say at which station should i change the lines. For example: A: Charing Cross; B: Westminster; Change at: Embankment&lt;/p&gt;</content>
		<author>
			<name>Kisivan</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Forward chaining in YAP Prolog?</title>
		<link href="http://stackoverflow.com/questions/10466682/forward-chaining-in-yap-prolog"/>
		<id>http://stackoverflow.com/q/10466682</id>
		<updated>2012-05-06T01:07:28+00:00</updated>
		<content type="html">&lt;p&gt;I need to use a forward chainer in certain Prolog problem. 
I would like to avoid to implement it my self from scratch with a vanilla meta-interpreter (but that is what I will have to do if no other option is available) since doing this with a meta-interpreter will be slow, and also I am sure that some good implementations should be around.
Does someone know if YAP or SWI Prolog includes a native and efficient forward chainer ?. If that is the case, a pointer to how to install it/use it would be greatly appreciated.&lt;/p&gt;

&lt;p&gt;In case no native forward chainer is available on these two Prolog engines, could someone recommend me a good open source implementation based on a vanilla meta-interpreter that I could use as an external Prolog library ?&lt;/p&gt;

&lt;p&gt;Thanks in advance.&lt;/p&gt;</content>
		<author>
			<name>Sergio</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">SWI-Prolog cgi_get_form(Arguments) saving and handling arguments web form</title>
		<link href="http://stackoverflow.com/questions/10428583/swi-prolog-cgi-get-formarguments-saving-and-handling-arguments-web-form"/>
		<id>http://stackoverflow.com/q/10428583</id>
		<updated>2012-05-05T08:50:10+00:00</updated>
		<content type="html">&lt;p&gt;I'm looking for a way of saving and after handling the arguments of a web form in SWI-Prolog when I submit the form and I call the same program to generate another form and so on. Always calling the same prolog program from one form to the next one.&lt;br /&gt;
The CGI SWI-Prolog library saves these arguments as a list of Name(Value) terms, i.e &lt;code&gt;[Name(Value)]&lt;/code&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;if I pass the arguments like a hidden argument inside the form (TotalArguments is a list): &lt;br /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;format('&quot;&amp;lt;&quot;input type=&quot;hidden&quot; id=&quot;nameofform1&quot; name=&quot;nameofform1&quot; value=&quot;~w&quot; /&gt;~n', TotalArguments),&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I need to get rid of the id or name that concatenates on my resultant list on TotalArguments when I append it. Any idea of how to do this so that the final list looks like &lt;code&gt;[nameofform1(value1), nameofform2(value2),...]&lt;/code&gt;?&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I could also write this list of arguments and append it into a file, and consult it every time the program is called again, but this will load them always and I only need to load the arguments needed in the specific step and form handled at the moment. Because otherwise this file could contain undesirable info after some executions. Any thoughts on how to do it this way?&lt;br /&gt;
Any other suggestions for this kind of problem?&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Edit with my solution using hidden form&lt;/strong&gt;&lt;br /&gt;
I've solved it by creating:&lt;br /&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre&gt;&lt;code&gt;  extract_value([],_).
  extract_value([A0|__ ], Valor) :-
     A0 =.. [_, Value],
     Valor is Value.
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;and then doing:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;extract_value(Arguments, Value),&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and submiting the hidden value of the form like:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;format('&amp;lt;&quot;input type=&quot;hidden&quot; id=&quot;nameofform1&quot; name=&quot;nameofform1&quot; value=&quot;~w&quot;/&gt;~n', [Value]),&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and appending it in the next form so that it looks how I wanted:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;[nameofform2(value2),nameofform1(value1)]&lt;/p&gt;
&lt;/blockquote&gt;</content>
		<author>
			<name>manullamas</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog construction of a list using =../2</title>
		<link href="http://stackoverflow.com/questions/10456502/prolog-construction-of-a-list-using-2"/>
		<id>http://stackoverflow.com/q/10456502</id>
		<updated>2012-05-05T08:05:47+00:00</updated>
		<content type="html">&lt;p&gt;I want to construct from a list like this: &lt;code&gt;[name1(value1), name2(value2),...]&lt;/code&gt; a list like this: &lt;code&gt;[value1, value2,...]&lt;/code&gt;, and I have the following code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    construct_listv([],_).
    construct_listv([A0|T], Values) :-
        A0 =.. [_, Value],
        append([Value], [], Values),
        construct_listv(T, Values).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;if I put for example &lt;code&gt;construct_listv([su(2), se(5)], ResultList)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;can anyone tell me why the second call to append fails and the correct way to do it?&lt;/p&gt;</content>
		<author>
			<name>manullamas</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">How do I express this logic?</title>
		<link href="http://stackoverflow.com/questions/6713424/how-do-i-express-this-logic"/>
		<id>http://stackoverflow.com/q/6713424</id>
		<updated>2012-05-04T18:43:55+00:00</updated>
		<content type="html">&lt;p&gt;I am having trouble trying to express certain types of information using clojure/core.logic so that the information is readily available and can be queried. Take the following as an example:&lt;/p&gt;

&lt;p&gt;Red robotic birds are only composed of buttons, cheese, and wire.&lt;/p&gt;

&lt;p&gt;Note the following:
I want to express that a class of birds, birds that are red and robotic, have a property.
This property is that they are composed only of buttons, cheese, and wire. There are no restrictions on the type of wire cheese or buttons. Also as a result, it should be deducible that there are no red robotic birds that are composed of paper. Also, these birds can be composed of a subset of the items buttons, cheese, and wire.&lt;/p&gt;

&lt;p&gt;In clojure/core.logic.prelude, there are relations and facts using defrel and fact.
However, I can't come up with a combination to explain this fact. Mainly to describe a fact about a subset of a class of objects, and how to declare that an object has a property that consists of other properties.&lt;/p&gt;

&lt;p&gt;How does one approach and solve this problem?&lt;/p&gt;</content>
		<author>
			<name>bmillare</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog: list of numbers</title>
		<link href="http://stackoverflow.com/questions/7432156/prolog-list-of-numbers"/>
		<id>http://stackoverflow.com/q/7432156</id>
		<updated>2012-05-04T13:36:16+00:00</updated>
		<content type="html">&lt;p&gt;How can I generate a list of numbers from 1 to N, where N &gt;= 0?&lt;/p&gt;

&lt;p&gt;Predicate: numbers(N, L).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;?-­ numbers(5,X).

X = [1, 2, 3, 4, 5].

?­- numbers(0,X).

X = [].
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>James</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Make a prolog BST from a list and return it in the parameter</title>
		<link href="http://stackoverflow.com/questions/10342224/make-a-prolog-bst-from-a-list-and-return-it-in-the-parameter"/>
		<id>http://stackoverflow.com/q/10342224</id>
		<updated>2012-05-04T12:15:26+00:00</updated>
		<content type="html">&lt;p&gt;I need to make a prolog predicate &lt;code&gt;from_list/2&lt;/code&gt; so that if i call &lt;code&gt;from_list([], T)&lt;/code&gt; I will get back a tree containg the items in the list(ints) so far I have:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;from_list([], empty).
from_list([X], T) :-
    insert(X, empty, T).
from_list([X|Y], T) :-
    from_list(Y, NT),
    insert(X, NT, T).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;edit: figured it out, but it is adding them to the tree in reverse order of the list. Any help?&lt;/p&gt;

&lt;p&gt;Here is my insert predicate, which seems to work just fine.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;insert( X, empty, bt(X, empty, empty) ). 
insert( X, bt(X2, L, R), bt(X2, NL, R) ) :-
    X &amp;lt; X2,
    !,
    insert(X, L, NL). 
insert( X, bt(X2, L, R), bt(X2, L, NR) ):-
    insert(X, R, NR).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And not also a second, much smaller question which doesn't NEED an answer&lt;/p&gt;

&lt;p&gt;I know prolog has a very elegant style when used properly...and this code...not so elegant...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;is_search(empty).
is_search( bt(_, empty, empty) ).
is_search( bt( X, empty, bt(Y,LEFT,RIGHT) ) ) :-
    X &amp;lt; Y,
    is_search(LEFT),
    is_search(RIGHT).
is_search( bt(X, bt(Y,LEFT,RIGHT), empty) ) :-
    X &amp;gt; Y,
    is_search(LEFT),
    is_search(RIGHT).
is_search( bt( X, bt(Y,L1,R1), bt(Z, L2, R2) ) ) :-
    X &amp;gt; Y,
    X &amp;lt; Z,
    is_search( bt(Y, L1, R1) ),
    is_search( bt(Z, L2, R2) ).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Any tips on how to clean that up a little?&lt;/p&gt;</content>
		<author>
			<name>Andrew Cooper</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Pairs in a list of lists prolog</title>
		<link href="http://stackoverflow.com/questions/10440844/pairs-in-a-list-of-lists-prolog"/>
		<id>http://stackoverflow.com/q/10440844</id>
		<updated>2012-05-04T06:22:11+00:00</updated>
		<content type="html">&lt;p&gt;I have to find all possible pairs in a list, the following way:&lt;/p&gt;

&lt;p&gt;given a list L=[[1,1,1],[1,2,1],[2,1,1],[2,2,1],[3,1,1],[3,2,1]]&lt;/p&gt;

&lt;p&gt;[1,1,1] has pairs [1,1],[1,1],[1,1]&lt;/p&gt;

&lt;p&gt;[1,2,1] has pairs [1,2],[2,1] because [1,1] was already found&lt;/p&gt;

&lt;p&gt;[2,1,1] has pairs [2,1],[2,1] these are not the same because they are located at different positions&lt;/p&gt;

&lt;p&gt;[2,2,1] has pairs [2,2] the other pairs have been found&lt;/p&gt;

&lt;p&gt;[3,1,1] has pairs [3.1] [3,1]&lt;/p&gt;

&lt;p&gt;[3,2,1] has pairs [3,2]&lt;/p&gt;

&lt;p&gt;I have a predicate that makes all possible pairs but I doesn't do it this way. I'm new to prolog and I don't know what else to do. This is what I have:&lt;/p&gt;

&lt;p&gt;It also returns the number of pairs created&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;do_pairs(L,PL,N):- do_pairs1(L,[],PL),len(PL,N).
do_pairs1([],L,L) :- !.
do_pairs1([H|T],Pairs,PL):-
     pairs(H,P),
     do_pairs1(T,[P|Pairs],PL)
    .

pairs(L,Pairs):- findall({I-J}, (member(I,L), member(J,L),I=&amp;lt;J), Pairs).
&lt;/code&gt;&lt;/pre&gt;</content>
		<author>
			<name>xKalelX</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog help removing or skipping an item whilst appending</title>
		<link href="http://stackoverflow.com/questions/10431402/prolog-help-removing-or-skipping-an-item-whilst-appending"/>
		<id>http://stackoverflow.com/q/10431402</id>
		<updated>2012-05-03T23:34:50+00:00</updated>
		<content type="html">&lt;p&gt;How do you skip a specific word if its part of a list and then append the rest? 
Usually this item is at the start of the list and sometimes it isn't so how would I work around this?&lt;/p&gt;</content>
		<author>
			<name>John Lam</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog - Assert into a new database</title>
		<link href="http://stackoverflow.com/questions/10437943/prolog-assert-into-a-new-database"/>
		<id>http://stackoverflow.com/q/10437943</id>
		<updated>2012-05-03T21:38:36+00:00</updated>
		<content type="html">&lt;pre&gt;&lt;code&gt;:-dynamic listofQuestions/2.
myrule:-
    write('P = '), write(Percent), write('-'),write(X),
    ( listofQuestions(Percent,X) -&amp;gt; true ; assert(listofQuestions(Percent,X)) ),
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The code snippet might not be required to answer my question.&lt;/p&gt;

&lt;p&gt;I want to assert to a blank 'listofQuestions' everytime I call my rule. This only happens if I close my prolog window and restart it. &lt;/p&gt;

&lt;p&gt;Any suggestions?&lt;/p&gt;</content>
		<author>
			<name>HungryCoder</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Uses of non-ground facts in Prolog?</title>
		<link href="http://stackoverflow.com/questions/1725444/uses-of-non-ground-facts-in-prolog"/>
		<id>http://stackoverflow.com/q/1725444</id>
		<updated>2012-05-03T19:07:04+00:00</updated>
		<content type="html">&lt;p&gt;In Prolog you can write a ground fact as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;lost(jen).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can also write a non-ground fact as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;lost(X).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Does this makes any sense? Could you show me a practical/real example where non ground facts are used?&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;</content>
		<author>
			<name>Juanjo Conti</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">How to find string length using prolog</title>
		<link href="http://stackoverflow.com/questions/10431130/how-to-find-string-length-using-prolog"/>
		<id>http://stackoverflow.com/q/10431130</id>
		<updated>2012-05-03T18:03:48+00:00</updated>
		<content type="html">&lt;p&gt;I have got a method length(list,var) which gives me the length of a list but i want to find the length of a String, anyone with a solution ?&lt;/p&gt;</content>
		<author>
			<name>Rishabh</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">prolog sort and print best 3</title>
		<link href="http://stackoverflow.com/questions/10435565/prolog-sort-and-print-best-3"/>
		<id>http://stackoverflow.com/q/10435565</id>
		<updated>2012-05-03T18:00:55+00:00</updated>
		<content type="html">&lt;p&gt;what I have now is,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   :-dynamic listofPeople/2.
    listofPeople(Mark,Name).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;e.g.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;     19, 'Jos'
     92, 'Abdul'
     33, 'Izz'
     16, 'Xin'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I want it like this -&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;92, 'Abdul'
33, 'Izz'
19, 'Jos'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which basiclly contains the mark for each student.&lt;/p&gt;

&lt;p&gt;I want to print the best 3 marks.&lt;/p&gt;

&lt;p&gt;To do that, I blv I have to do sorting. If I do sorting, I will lose the order of the name of the student.&lt;/p&gt;

&lt;p&gt;As you can understand by default, what I want is to sort only the marks and change the names position according to the marks as well, so when i print&lt;/p&gt;

&lt;p&gt;i get the above output&lt;/p&gt;

&lt;p&gt;Code snippets appreciated.&lt;/p&gt;</content>
		<author>
			<name>HungryCoder</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Writing A Prolog Parser</title>
		<link href="http://stackoverflow.com/questions/10434002/writing-a-prolog-parser"/>
		<id>http://stackoverflow.com/q/10434002</id>
		<updated>2012-05-03T17:40:47+00:00</updated>
		<content type="html">&lt;p&gt;I'm trying to write a simple parser for a grammar.  The parser does not need to create a parse tree, only recognize if a sentence matches the grammar.  So far, I have the following predicates, using DCG notation:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    program--&amp;gt;[].
    program--&amp;gt;stmt_list.
    stmt_list--&amp;gt;stmt,stmt_list.
    stmt--&amp;gt;[id,:=],expr;[read],[id];[write],expr.
    expr--&amp;gt;term, term_tail.
    term_tail--&amp;gt;add_op,term,term_tail.
    term_tail--&amp;gt;[].
    term--&amp;gt;factor, factor_tail.
    factor_tail--&amp;gt;mult_op, factor, factor_tail.
    factor_tail--&amp;gt;[].
    factor--&amp;gt;[(expr)].
    factor--&amp;gt;[id].
    factor--&amp;gt;[number].
    add_op--&amp;gt;[+].
    add_op--&amp;gt;[-].
    mult_op--&amp;gt;[*].
    mult_op--&amp;gt;[/].
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using a query such as program([read,id],[]). I should be getting a true response, but I am getting a false one.  What is missing that is causing this?  Thank you for your help.&lt;/p&gt;</content>
		<author>
			<name>jldavis76</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog simple sort</title>
		<link href="http://stackoverflow.com/questions/10434938/prolog-simple-sort"/>
		<id>http://stackoverflow.com/q/10434938</id>
		<updated>2012-05-03T17:33:56+00:00</updated>
		<content type="html">&lt;p&gt;In Prolog, what I have now is,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:-dynamic listofPeople/2.
listofPeople(Mark,Name).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which basically contains the mark for each student.&lt;/p&gt;

&lt;p&gt;I want to print the best 3 marks.&lt;/p&gt;

&lt;p&gt;To do that I believe I have to do sorting. If I do sorting, I will lose the order of the name of the student. &lt;/p&gt;

&lt;p&gt;As you can understand by default, what I want is sort only the marks and sort the names according to the marks as well.&lt;/p&gt;

&lt;p&gt;Please help. Code snippets appreciated.&lt;/p&gt;</content>
		<author>
			<name>HungryCoder</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Prolog falling into infinite loop</title>
		<link href="http://stackoverflow.com/questions/10426875/prolog-falling-into-infinite-loop"/>
		<id>http://stackoverflow.com/q/10426875</id>
		<updated>2012-05-03T11:39:33+00:00</updated>
		<content type="html">&lt;p&gt;I have two problems that have bugged me for hours. &lt;code&gt;connected/2&lt;/code&gt; is supposed to judge whether two people are connected or not; &lt;code&gt;distance/3&lt;/code&gt; is supposed to measure the kinship. But:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I keep getting &lt;code&gt;true&lt;/code&gt;s infinitely for the query &lt;code&gt;connected(x,y)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;and I'm getting infinitely increasing &lt;code&gt;N&lt;/code&gt; for &lt;code&gt;distance(x,y,N)&lt;/code&gt; query. Any suggestions?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here are my facts:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;male(ted).
male(barney).
male(ranjit).
male(marshall).
male(tony).
male(swarley).
male(steve).
male(chuck).
male(john).
male(devon).
male(morgan).

female(robin).
female(lily).
female(wendy).
female(stellar).
female(abby).
female(victoria).
female(carina).
female(sarah).
female(ellie).

married(ted,      robin).
married(marshall, lily).
married(ranjit,   wendy).
married(stellar,  tony).
married(steve,    carina).
married(sarah,    chuck).
married(ellie,    devon).

father(ted,      barney).
father(ted,      ranjit).
father(marshall, wendy).
father(ranjit,   stellar).
father(tony,     abby).
father(tony,     swarley).
father(tony,     victoria).
father(steve,    chuck).
father(steve,    ellie).
father(chuck,    john).
father(devon,    morgan).

mother(robin,    barney).
mother(robin,    ranjit).
mother(lily,     wendy).
mother(wendy,    stellar).
mother(stellar,  abby).
mother(stellar,  swarley).
mother(stellar,  victoria).
mother(carina,   chuck).
mother(carina,   ellie).
mother(sarah,    john).
mother(ellie,    morgan).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, my predicates:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).

son(X,Y) :-
    male(X),
    parent(Y,X).

daughter(X,Y) :-
    female(X),
    parent(Y,X).

sibling(X,Y) :-
    parent(Z,X),
    parent(Z,Y).

cousin(X,Y) :-
    parent(Z,X),
    parent(W,Y),
    parent(G,Z),
    parent(G,W).

ancestor(X,Y) :-
    parent(X,Z),
    ancestor(Z,Y).
ancestor(X,Y) :- parent(X,Y).

notmember(X,[]).
notmember(X,[H|T]) :- 
    X \= H,
    notmember(X,T).

connected(X,Y,_) :- X == Y.
connected(X,Y,Visited) :- 
    ancestor(X,Z),
    notmember(Z,Visited),
    connected(Z,Y,[Z|Visited]).
connected(X,Y,Visited) :- 
    ancestor(Z,X),
    notmember(Z,Visited),
    connected(Z,Y,[Z|Visited]).
connected(X,Y,Visited) :- 
    sibling(X,Z),
    notmember(Z,Visited),
    connected(Z,Y,[Z|Visited]).
connected(X,Y,Visited) :- 
    married(X,Z),
    notmember(Z,Visited),
    connected(Z,Y,[Z|Visited]).
connected(X,Y) :- connected(X,Y,[X]).

minimum(X,[X]).
minimum(X,[M,H|T]) :- 
    M =&amp;lt; H,
    minimum(X,[M|T]).
minimum(X,[M,H|T]) :-
    M &amp;gt; H,
    minimum(X,[H|T]).

distance(X,X,_,0).
distance(X,Y,Visited,N) :- 
    parent(X,Z),
    notmember(Z,Visited),
    distance(Z,Y,[Z|Visited],N1),
    N is N1+1.
distance(X,Y,Visited,N) :- 
    parent(Z,X),
    notmember(Z,Visited),
    distance(Z,Y,[Z|Visited],N1),
    N is N1+1.
distance(X,Y,N) :- distance(X,Y,[],N).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;EDIT:
Thank you, i think i've managed to solve half way through the problems now.
Taking @twinterer's advice, I have fixed the predicates like this&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;connected(X,Y,_) :- X == Y.
connected(X,Y,V) :-
    married(X,Z),
    notmember(Z,V),
    connected(Z,Y,[Z|V]),!.
connected(X,Y,V) :-
    sibling(X,Z),
    notmember(Z,V),
    connected(Z,Y,[Z|V]),!.
connected(X,Y,V) :-
    parent(X,Z),
    notmember(Z,V),
    connected(Z,Y,[Z|V]),!.
connected(X,Y,V) :-
    parent(Z,X),
    notmember(Z,V),
    connected(Z,Y,[Z|V]),!.
connected(X,Y) :- connected(X,Y,[X]).

minimum(X,[X]).
minimum(X,[M,H|T]) :- 
    M =&amp;lt; H,
    minimum(X,[M|T]).
minimum(X,[M,H|T]) :-
    M &amp;gt; H,
    minimum(X,[H|T]).

count(X,[],0).
count(X,[X|T],N) :-
    count(X,T,N1),
    N is N1+1.
count(X,[H|T],N) :-
    X \== H,
    count(X,T,N1),
    N is N1.

distance(X,X,Visited,0) :-
    count(X,Visited,N),
    N =&amp;lt; 1, !.
distance(X,Y,Visited,N) :- 
    parent(X,Z),
    (notmember(Z,Visited)-&amp;gt;
        distance(Z,Y,[Z|Visited],N1),
        N is N1+1
    ;
        fail
    ),!.
distance(X,Y,Visited,N) :- 
    parent(Z,X),
    (notmember(Z,Visited)-&amp;gt;
        distance(Z,Y,[Z|Visited],N1),
        N is N1+1
    ;
        fail
    ),!.
distance(X,Y,N) :- 
    findall(N1,distance(X,Y,[X],N1),L),!,
    minimum(N,L),!.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But there is a new set of problems now &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;it can't take arbitrary queries like &lt;code&gt;distance(X,y,n)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;queries like &lt;code&gt;connected(X,y)&lt;/code&gt; return duplicate results&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think removing duplicate results can be achieved by using that &lt;code&gt;findall/3&lt;/code&gt; predicate, 
but I am clueless as to how I can actually implement it.&lt;/p&gt;</content>
		<author>
			<name>Kenny</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Tautology Checker for GNU Prolog</title>
		<link href="http://stackoverflow.com/questions/7058983/tautology-checker-for-gnu-prolog"/>
		<id>http://stackoverflow.com/q/7058983</id>
		<updated>2012-05-03T10:59:23+00:00</updated>
		<content type="html">&lt;p&gt;I am looking for &lt;strong&gt;open-source&lt;/strong&gt; implementations of tautology checkers written in GNU Prolog (implementation for SWI-Prolog is acceptable as well, but GNU Prolog is preferred).&lt;/p&gt;

&lt;p&gt;I'd like to feed program input with queries like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;A and (B or C) iff (A or B) and (A or C).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;3^2 * (X + 2) == (9 * X) + 18.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;of course, notation can be different, like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(3 power 2) mul (X plus 2) equals (9 mul X) plus 18.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What I expect as &lt;em&gt;result&lt;/em&gt;, is &lt;em&gt;boolean&lt;/em&gt; answer , like &quot;Yes/No&quot;, &quot;Equals/Different&quot;, &quot;Prove found/Failed to find prove&quot; or similar.&lt;/p&gt;

&lt;p&gt;I've found tautology checker for GNU-Prolog on &lt;a href=&quot;ftp://ftp.cs.yorku.ca/pub/peter/SVT/GNU/&quot; rel=&quot;nofollow&quot;&gt;ftp://ftp.cs.yorku.ca/pub/peter/SVT/GNU/&lt;/a&gt; , but licence is not attached and no clue how to apply &lt;a href=&quot;http://www.gprolog.org/manual/html_node/gprolog061.html&quot; rel=&quot;nofollow&quot;&gt;Gnu Prolog Arithmetic constraints&lt;/a&gt; and &lt;a href=&quot;http://www.gprolog.org/manual/html_node/gprolog030.html&quot; rel=&quot;nofollow&quot;&gt;Arithmetic&lt;/a&gt; capabilities in order to extend just logical model with arithmetic. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Any other simmilar solvers?&lt;/li&gt;
&lt;li&gt;Some examples how arithmetic capabilities might be used in order to extend model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks, Greg.&lt;/p&gt;

&lt;p&gt;P.S. According arithmetic, I am looking for partial support - I want to handle only some basic cases, which I can code by hand with simple heuristics (gnu-prolog integer functions examples welcome as well) if proposed solution will handle classical logic properly and open-source code will be nice to extend :).&lt;/p&gt;

&lt;p&gt;P.P.S As @larsmans noted, according to &lt;a href=&quot;https://secure.wikimedia.org/wikipedia/en/wiki/G%C3%B6del%27s_incompleteness_theorems&quot; rel=&quot;nofollow&quot;&gt;Gödel's incompleteness theorems&lt;/a&gt; there is no way to prove &quot;all&quot; formulas. That's why I am looking for something that proves, what can be proven from given set of axioms and rules, as I am looking for Gnu Prolog program, I am looking for examples of such sets of axioms and rules ;). Of course checker may fail - I am expecting it will work in &quot;some&quot; cases :). - On the other hand, there is &lt;a href=&quot;http://en.wikipedia.org/wiki/G%C3%B6del%27s_completeness_theorem&quot; rel=&quot;nofollow&quot;&gt;Gödel's completeness theorem&lt;/a&gt; ;).&lt;/p&gt;</content>
		<author>
			<name>Grzegorz Wierzowiecki</name>
			<uri>http://stackoverflow.com/questions/tagged/?tagnames=prolog&amp;sort=active</uri>
		</author>
		<source>
			<title type="html">active questions tagged prolog - Stack Overflow</title>
			<subtitle type="html">most recent 30 from stackoverflow.com</subtitle>
			<link rel="self" href="http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot"/>
			<id>http://stackoverflow.com/feeds/tag?tagnames=prolog&amp;sort=hot</id>
			<updated>2012-05-16T15:23:06+00:00</updated>
		</source>
	</entry>

</feed>

