% Based on
% https://occasionallycogent.com/continuations_in_prolog/

test(Cont, Term) :-
    writeln("Inside test"),
    reset(test_, Term, Cont),
    writeln("After reset").

test_ :-
    writeln("Entering reset"),
    shift(Y),
    X is 1 + (2 * Y),
    write("In test X = "), write(X), writeln("; done").

main :-
    test(Cont, Term),
    \+ \+ ( writeln("Calling Cont(2)"),
            Term = 2, call(Cont)),
    \+ \+ ( writeln("Calling Cont(4)"),
            Term = 4, call(Cont)).

:- initialization(main).
