feldman@Neon.Stanford.EDU (Todd J. Feldman) (03/02/90)
Can someone please help me with a bug in the following Prolog fragment: process_entries:- wait(X), abolish(wait,1), goal1(.....), goal2(.....), goal3(.....), goal4(.....). The intention I had in writing this code was for backtracking to occur between goals 1 and 4. Finally, goal1 will no longer be able to succeed. When it fails, I want backtracking to go to wait(X); as long as there is at least one wait fact (wait is not a rule; just facts) in the database, abolish them all, and begin with goal1 again; the existence of the wait facts is what caused goal1 to fail in the first place. In doing some amount of tracing, I've discovered that goal1 is failing as expected, the abolish is not backtracked to as expected, but that wait(X) is not resucceeding; it fails immediately on backtracking EVEN THOUGH THERE ARE SEVERAL wait(...) facts in the database! Any ideas? I'll be happy to provide more information if it would be helpful, and I'd be very grateful for any help you can give me! Thanks! Todd Feldman feldman@neon.stanford.edu -- wewewe 2323232
alberto@konark.cs.umd.edu (Jose Alberto Fernandez R) (03/02/90)
> process_entries:- > wait(X), > abolish(wait,1), > goal1(.....), > goal2(.....), > goal3(.....), > goal4(.....). > > The intention I had in writing this code was for backtracking to occur > between goals 1 and 4. Finally, goal1 will no longer be able to succeed. > When it fails, I want backtracking to go to wait(X); as long as there > is at least one wait fact (wait is not a rule; just facts) in the database, > abolish them all, and begin with goal1 again; the existence of the wait > facts is what caused goal1 to fail in the first place. In doing some > amount of tracing, I've discovered that goal1 is failing as expected, > the abolish is not backtracked to as expected, but that wait(X) is not > resucceeding; it fails immediately on backtracking EVEN THOUGH THERE > ARE SEVERAL wait(...) facts in the database! You don't need the ABOLISH to do what you want. Without it, Prolog will try each wait(X) clause only once, therefore you have what you want. If you want to delete these entries, so that no further execution will used it, you can do that with: process_entries:- wait(X), goal1(.....), goal2(.....), goal3(.....), goal4(.....). process_entries:- abolish(wait,1), fail. /* This fail is for maintain the patterns in the execution. */ Jose Alberto. -- :/ \ Jose Alberto Fernandez R | INTERNET: alberto@cs.umd.edu :| o o | Dept. of Computer Sc. | BITNET: alberto@cs.umd.edu :| ^ | University of Maryland | UUCP: {...}!mimsy!alberto :\ \_/ / College Park, MD 20742 |
feldman@Neon.Stanford.EDU (Todd J. Feldman) (03/02/90)
In article <ALBERTO.90Mar1190445@konark.cs.umd.edu> alberto@konark.cs.umd.edu (Jose Alberto Fernandez R) writes: >You don't need the ABOLISH to do what you want. Without it, Prolog >will try each wait(X) clause only once, therefore you have what you >want. > >If you want to delete these entries, so that no further execution will >used it, you can do that with: > >process_entries:- > wait(X), > goal1(.....), > goal2(.....), > goal3(.....), > goal4(.....). > >process_entries:- > abolish(wait,1), > fail. /* This fail is for maintain the patterns in > the execution. */ Yes, but if wait(X) succeeds, I want all the current wait(..) facts to be removed; otherwise goal1 will fail again. It's a weird situation, but another way to describe it would be that if anything is waiting, make them ready (by abolishing the wait facts) and proceed. Then when you done (i.e., goal1 fails again), if anything is waiting, make them ready, etc. The idea is that wait(..) facts may be asserted by goal4. Could you respond with any more help? Thanks! Todd
stefan@hpbbi4.HP.COM (#Stefan Bachert) (03/05/90)
Hello >process_entries:- > wait(X), > abolish(wait,1), > goal1(.....), > goal2(.....), > goal3(.....), > goal4(.....). This type of code is very implementation depending. As I understood you well, goal1 to goal4 may create a list of new tasks. This task description are implemented as wait(task). For this I recommend the following code fragments. pro:- repeat, task(X), % next task abolish(wait,1), % clear actual tasks pro2(X),!. % depending on what you expect by end % of task list add a fail pro2(end):-!. % no more tasks ( ! is not really neccessary) pro2(X):-goal1( ),goal2( ),goal3( ),goal4( ). % does goal4 allways fail ?? task(X):-wait(X),!. % only the first task will be taken ! task(end). Hope this will help you Stefan Bachert