Subject: Re: [SWIPL] no copy semantics for PlTerm, in the C++ interface

From: Jan Wielemaker <[email-masked]>
Date: Sun, 4 Nov 2001 14:08:03 +0100

> The class PlTerm in the C++ interface, SWI-cpp.h, contains this:
> 
>   int operator =(const PlTerm &t2)	/* term */
>   { return PL_unify(ref, t2.ref);
>   }
> 
> This is not correct copy semantics. You can't overwrite a PlTerm 
> object. You can't use PlTerm objects as values like this. For 
> instance, the Standard Template Library relies on correct copy 
> semantics. You couldn't store PlTerm's in STL containers, etc.
> 
> I suggest renaming the operator=() methods to unify().

I never claimed to be a C++ expert.  = has been redefined to allow
natural unification from C++.  I guess you'd like to see

   int operator =(const PlTerm &t2)	/* term */
   { return PL_put_term(ref, t2.ref);
   }

I think I agree to your proposal, also because = is a bit strange
and leads to

	return X = Y;

rather then the possibly someway clearer:

	return X.unify(Y);

Big problem is that there is a lot of code around that will break
if we change this.  Adding unify() is of course trivial.  The only
compatibility solution I can see is:

#define PL_UNIFY_WITH_IS 1
#include <SWI-cpp.h>

to be able to load old code.  

	Comments from C++ users and experts?

		--- Jan