[Previous] [Up] [Next]
Go backward to Tracing and Debugging Programs
Go up to Top
Go forward to Notes on Programming Style

What to Do When You Have Called a Left-recursive Clause

If you have loaded a program, made a query, and the interpreter seems to take forever to respond, you have probably made a mistake somewhere which makes the program left recursive (it is "looping"). This happens to everyone--don't panic!

If you suspect that the interpreter may be stuck in an infinite loop, send the interrupt signal C-c C-c to the shell.

The interrupt signal is in fact C-c--this is what you would use if you ran SICStus from a Unix shell. However, Emacs already uses C-c for other purposes, so to be able to address the Unix process, you prefix the signal. The prefix that does this is also C-c--this is why you have to type C-c twice.

The goal that the interpreter is currently trying to prove is displayed, followed by the line:
Prolog interruption (h for help)?
You have several options at this point (you can see them all by typing h). If it is obvious what the problem with the code is, ABORT the current goal by typing a. This terminates the query, and the returns | ?-. If for some reason you would want to exit the interpreter completely, type e instead.

If nothing was wrong and the query was simply taking a long time to process, type c for continue, or if you are not sure, start tracing by typing t (there are a few more options: BREAKING and DEBUGGING, which are handy when you become more adept at debugging programs--see Tracing and Debugging. When you trace, the interpreter shows the current goal, followed by the prompt ?. There are a number of commands you can type at this prompt (see Tracing and Debugging. for the details). The basic ones are carriage return, which shows the next goal, a which aborts the query, and n which switches tracing off and continues the execution.

If you suspect that the interpreter is stuck in an infinite loop, interrupt the execution as soon as possible! While Prolog is still trying to execute the left-recursive procedure, it uses up the machine's resources very rapidly, and the other people who are logged on to the same machine will have their processes slowed down.

Summary of What To Do

  1. Type C-c C-c to interrupt the process.
  2. Find out what the problem is by tracing (type t at the prompt).
  3. When you know what the problem is, type a for abort.
  4. Edit the program to remove the left-recursive procedure.


[Previous] [Up] [Next]