next up previous
Next: 15.2 Ancestor cut Up: 15 Direct binary clause Previous: 15 Direct binary clause

15.1 Standard Prolog catch and throw

BinProlog 5.75 implements also Standard Prolog's catch/throw mechanism, using a similar technique (thanks to Bart Demoen!), which works as follows:

catch(Goal,Ball,Do):-
  execute Goal
  on throw(Term): look for closest catch
     copy Term
     undo bindings until call to catch; remove choices
     unify with Ball
        if fail: throw Ball again
        if succeed: call Do, continuation of catch goal

Note that our continuations and linear assumption based implementation ensures constant time execution of catch and throw, without actual stack scanning.



next up previous
Next: 15.2 Ancestor cut Up: 15 Direct binary clause Previous: 15 Direct binary clause



Paul Tarau
Thu Apr 3 10:26:39 AST 1997