[comp.lang.prolog] Freezing and Copyterm

mwc@aipna.ed.ac.uk (Matthew Crocker) (08/14/90)

Hello,
  I'm having a problem with the goal freezing directive, which is
  illustrated by the code below. Roughly, while do1 is waiting for X
  to be instantiated, do2 creates Y -- a copy of X -- and instantiates
  Y = 2. This seems to "fake-out" the freeze, which thinks that X
  is now instantiated as 2. Afterwards, however, when X is set to 1
  do1 executes again (it almost looks like X is receiving multiple
  assignments, since do1 prints it's value as 2 then 1).

  A response from SICStus (Mats Carlsson) pointed out that copyterm
  also copies the any constraints (as does the usual assert/retract
  version of copyterm).

  Is this intended? Are there any alternatives to copy_term(X,Y) which
  create a Y truly independent of X.

Matt Crocker
mwc@aipna.ed.ac.uk
---------------------
%SICStus Prolog: test of freeze.
main :-
   do1(X),
   do2(X),
   X=1.

:- wait do1/1.
do1(X) :-           %When X gets instantiated, print it.
   write(X).

do2(X) :-
   copy_term(X,Y),  Ccreate an independent copy of X.
   Y=2.