Picat Picat Exception Handling and Debugging 2 — Questions and Answers
Question 1: Which built-in activates Picat's execution tracer for debugging?
- debug()
- trace (Correct answer)
- spy_all
- set_trace(on)
Correct answer: trace
`trace` activates the Picat tracer, printing each goal as it is called, exited, or failed.
Question 2: What does `spy(Predicate)` do in Picat?
- Sets a breakpoint on a specific predicate (Correct answer)
- Monitors memory allocation
- Logs all calls to a log file
- Prevents a predicate from backtracking
Correct answer: Sets a breakpoint on a specific predicate
`spy(Predicate)` sets a spy point so the debugger activates only when that predicate is called.
Question 3: Which predicate prints the current execution call stack in Picat?
- print_stack()
- backtrace
- print_backtrace (Correct answer)
- show_stack()
Correct answer: print_backtrace
`print_backtrace` prints the current execution stack, which is helpful for diagnosing errors.
Question 4: How do you measure the execution time of a goal in Picat?
- time(Goal) (Correct answer)
- measure(Goal, Time)
- timer(Goal)
- benchmark(Goal)
Correct answer: time(Goal)
`time(Goal)` executes Goal and prints the elapsed wall-clock time and inference count.
Question 5: What does `listing(Predicate)` display in Picat's interactive session?
- All files in the working directory
- The source clauses of the named predicate (Correct answer)
- All currently defined predicates
- The call graph of the predicate
Correct answer: The source clauses of the named predicate
`listing(Predicate)` prints all source clauses for the specified predicate to standard output.
Question 6: Which flag setting causes Picat to throw an error when an undefined predicate is called?
- unknown = error (Correct answer)
- undefined_pred = true
- strict_mode = on
- error_on_undefined = true
Correct answer: unknown = error
Setting the `unknown` flag to `error` causes Picat to throw `existence_error` for undefined predicate calls.
Which built-in activates Picat's execution tracer for debugging?