Created
February 26, 2016 08:38
-
-
Save TeamSPoon/5fe002f65a5d843a7e97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I thought something like this already existed somewhere? | |
But anyhow it doesn't right? | |
Though how should this be written? Byrd box? debugger model? | |
*/ | |
call_while(Setup,Goal,Undo):- | |
once(Setup), | |
(Goal | |
*-> | |
(once(Undo);(once(Setup),fail)) | |
; | |
(Undo,!,fail)). | |
/ *Example usages: */ | |
with_prolog_flag(Flag,Value,Goal):- | |
current_prolog_flag(Flag,Was), | |
call_while( set_prolog_flag(Flag,Value), | |
Goal, | |
set_prolog_flag(Flag,Was)). | |
% Trace that is not like once/1 | |
no_trace(Goal):- | |
( | |
notrace((tracing,notrace)) | |
-> | |
('$leash'(OldL, OldL), | |
'$visible'(OldV, OldV), | |
call_while( | |
notrace((visible(-all),leash(-all),leash(+exception),visible(+exception))) | |
Goal, | |
notrace(('$leash'(_, OldL),'$visible'(_, OldV),trace)))) | |
; | |
Goal). | |
% Trace non interactively | |
with_trace_non_interactive(Goal):- | |
( tracing-> Undo=trace ; Undo = notrace ), | |
'$leash'(OldL, OldL), | |
'$visible'(OldV, OldV), | |
call_while( | |
notrace((visible(+all),leash(-all),leash(+exception),trace)), | |
Goal, | |
notrace(('$leash'(_, OldL),'$visible'(_, OldV),Undo))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment