-Var := +body_term

The assignment operator creates a copy of its right operand and assigns it to the left operand. This means that the left operand must be a variable (or a variable that has a value), any value that the left operand may have is overwritten by the copy of the right operand.

If the right operand contains a variable then the value of that variable is copied, not a reference to the variable. If the right operand contains an empty variable an exception is thrown. This operator is not part of the Prolog standard.

Arrow.gif (1632 bytes) The assignment operator does not create a copy of an instance of a class if a variable in the right operand refers to an instance. This can prevent a module from being closed because instances of a class may still exist, i.e. they exist in the expression copied by the :=/2 operator. To solve this problem the variable that contains the expression with the reference to the instance in it must receive another value.

 

Examples
A := [B], B=c. the variable A will have the value [B]
B=[b], A := [a|B]. A will be the list [a, b]
B=[b], C=[], A := [B,a|C]. A will be the list A=[[b], a]
B=a, B := [x|B]. B will have the value [x| a]

 

Exceptions
the left operand is not a variable a type_error(variable, A) exception is thrown, the variable A is replaced by the left operand
the right operand is a single empty variable OR contains an empty variable an instantiation_error exception is thrown

 

 

info@trinc-prolog.com