From jan@swi.psy.uva.nl Wed Sep 26 15:54:03 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8QDs3v23999;
	Wed, 26 Sep 2001 15:54:03 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f8QDs3V19018;
	Wed, 26 Sep 2001 15:54:03 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Broudo Nissim <nissim@math.ufl.edu>,
   SWI-Prolog mailing list <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] Un-binding
Date: Wed, 26 Sep 2001 15:48:46 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <Pine.GSO.4.21.0108211430110.653-100000@oneida.math.ufl.edu>
In-Reply-To: <Pine.GSO.4.21.0108211430110.653-100000@oneida.math.ufl.edu>
MIME-Version: 1.0
Message-Id: <0109261554020R.15353@gollem>
Content-Transfer-Encoding: 8bit

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

