1:- module(ccreader, [ run_reader/3, ask/2 ]).

Essentially, direct style reader monad.

*/

    6:- use_module(library(delimcc), [p_reset/3, p_shift/2]).    7
    8:- set_prolog_flag(generate_debug_info, false).    9
   10ask(Pr,X) :- p_shift(Pr,X).
   11
   12:- meta_predicate run_reader(+,0,?).
 run_reader(+Pr:prompt, +P:pred, X:A) is det
Run P in an context that allows read/2 to be used to access X.
   16run_reader(Prompt, Goal, X) :-
   17   p_reset(Prompt, Goal, Status),
   18   cont_reader(Status, Prompt, X).
   19
   20cont_reader(done,_,_).
   21cont_reader(susp(X,Cont), Prompt, X) :- run_reader(Prompt, Cont, X)