<div class="notebook"> <div class="nb-cell markdown" name="md1"> # Prolog: critical section, backtracking, error handling See https://stackoverflow.com/questions/43390782/prolog-critical-section-backtracking-error-handling </div> <div class="nb-cell program" name="p1"> until_failure((A,B), Result) :- !, until_failure(A, Result), ( var(Result) -> until_failure(B, Result) ; true ). until_failure(G, Result) :- ( catch(G, Result, true) *-> true ; Result = false(G) ). </div> <div class="nb-cell query" name="q1"> until_failure((Step1 = true, Step2 = true, fail, Step3 = true), Result), writeln([Step1, Step2, Step3]). </div> </div>