Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!udel!rochester!uhura.cc.rochester.edu!lm03_cif From: lm03_cif@uhura.cc.rochester.edu (Larry Moss) Newsgroups: comp.lang.prolog Subject: help novice prolog users Keywords: sbprolog Message-ID: <5249@ur-cc.UUCP> Date: 14 Feb 90 19:57:03 GMT Reply-To: lm03_cif@uhura.cc.rochester.edu (Larry Moss) Organization: University of Rochester Lines: 66 I've revcently been woriking with sbprolog and the Turbo Prolog manuals for reference so I'm running into some problems. The manuals are borowed and I have much more access to the system with sbprolog than an IBM PC. I can sayu fairly confidently that I know the language but don't know how to use it. Here are the problems - I have a database that looks like the following. - parent(grandad, dad). parent(dad, son). child(mom, grandad). child(X, Y) :- parent(Y, X). descend(X, Y) :- parent(Y, X). descend(X, Y) :- descend(X, Z), parent(Y, Z). - 1. If I use a statement like "descend(son, grandad)" it works fine, but if I want to list all of the descendants found in a database like in "descend(X,grandad)", it never terminates. I can put a cut in the line "descend(X, Y) :- parent(Y, X), !." and have it terminate but it will terminate after the first match. Is there a way for me to write this so I can get a compete list of all of the descendants of a particular person and still have it terminate? 2. I also want to add the line parent(X,Y) :- child(Y,X). but I have child(X, Y) :- parent(Y, X). this would cause infinite recursion. Is there a correct way for me to do this? ============= second problem - hanoi(N) :- move(N, left, middle, right). move(1, A, _, C) :- inform(A, C), !. move(N, A, B, C) :- N1 = N - 1, move(N1, A, C, B), inform(A, C), move(N1, B, A, C). inform(Loc1, Loc2) :- write(Loc1), tab(5), write(Loc2), nl. - This comes directly out of the Turbo Prolog manual. I assume it works with Turbo Prolog, but I haven't had the opportunity to try it. It will solve hanoi(1), but anything greater than that just puts a nice big core in my directory. What can I do to make this work in sbprolog? Thanks in advance, Larry -- lm03_cif@uhura.cc.rochester.edu / CLARKE'S THIRD LAW: lmo3_ss@db1.cc.rochester.edu / Any sufficiently advanced technology is lmo3_ss@uordbv.bitnet / indistinguishable from magic.