Subject: Re: [SWIPL] Un-binding

From: Jan Wielemaker <[email-masked]>
Date: Wed, 26 Sep 2001 15:48:46 +0200

On Tue, 21 Aug 2001, Broudo  Nissim wrote:
>I would like to call a predicate twice, each time one of the predicate's
>arguments bound to different constants:
>
>my_pred(constant_1, X)
>my_pred(constant_2, X)
>
>But when I bind the second time (with PL_unify_atom_chars), I cannot get
>constant_2 to bind.
>
>Here is my code:
>
>char *constant_1 = "constant_1"
>char *constant_2 = "constant_2"
>term_t v         = PL_new_term_refs(2)
>PL_unify_atom_chars(v, constant_1);
>predicate_t pred = PL_predicate("my_pred", 2, NULL);
>qid_t qid        = PL_open_query(NULL, PL_Q_NORMAL, pred, v);
>PL_next_solution(qid);
>PL_unify_atom_chars(v,constant_2);
>PL_next_solution(qid);
>
>The second solution is identical to the first, becuase the second
>PL_unify_atom_chars cannot bind a constant to an already bound
>variable.  Is there any way to "unbind" a variable ?

You can use PL_put_* to overide bindings of term-references from
the C-interface.  I wouldn't really advice it in this case though.
I don't think it will crash, but it still isn't legal to modify
bindings of term-references while in use by an active goal and
the results may sometimes surprise you.

Probably you want to close to query, rebind the variable (which
you can do using the PL_put_* functions), reopen te query and
try to prove it again.  Between PL_next_solution() calls, the
only sensible thing to do is read the bindings of one or more
of the arguments.

	Regards --- Jan