We discuss how to implement backjumping (or intelligent backtracking) in Prolog by using the built-ins throw/1 and catch/3. We show that it is impossible in a general case, contrary to a claim that ``backjumping is exception handling". We provide two solutions. One works for binary programs; in a general case it imposes a restriction on where backjumping may originate. The other restricts the class of backjump targets. We also discuss implementing backjumping by using backtracking and the Prolog database. Additionally, we explain the semantics of Prolog exception handling in the presence of coroutining.
翻译:我们讨论如何通过使用内置谓词throw/1和catch/3在Prolog中实现回跳(或称智能回溯)。与"回跳即异常处理"这一论断相反,我们证明了一般情况下不可能实现回跳。我们提供了两种解决方案:一种适用于二元程序,但在一般情况下会限制回跳的发起位置;另一种则限制了回跳目标类别的范围。我们还讨论了利用回溯和Prolog数据库实现回跳的方法。此外,我们解释了存在协同调度时Prolog异常处理的语义。