On 03/16/2016 11:47 AM, Jan Rosecký wrote:
> Hello!
> I am struggling with the following: I need to cut a choice point
> depending on a result I get after the choice. If any other choice points
> have been created since then, I need to *preserve* them. E.g.:
>
> |
> member(A,[a,b]),member(B,[1,2]),%here I need to decide,whether to cut
> the first member (e.g.according to the result of the second member).
> |
>
> prolog_cut_to does not really help here, does it? Obviously, it could be
> possible to overcome with asserts/flags but is it possible even without
> these?
As it stands, that doesn't exist. Its not that useful as it typically
does not allow you to reclaim space unless you implement stack
compaction for the local stack. Implementing it isn't that hard,
basically use the choice-point examination predicates to find the proper
source code and add a foreign predicate that changes the type of the
choice point into CHP_DEBUG.
Instead of flags, you probably want to use non-backtrakable data. E.g.,
you can do
State = can_backtrack(true),
( Something
; arg(1, State, true),
Else
),
More(State).
Then inside More: nb_setarg(1, State, false). As we cannot reclaim space
easily anyway, this isn't much worse than being able to kill a specific
choice point.
Cheers --- Jan