Global Variable Version 2 - Nondestructive - User Guide

We have previously learned about destructive operators in Version 1 of Global Variables. Now we are going to take a look at nondestructive opeators. We are going to take a look back at some examples of destructive operators first. Then we will show the following:

Destructive Operators in Arithmatic Equations

Key: These are called destructive because they replace the global variable with the answer to the arithmatic equation.
Example:
In gv1.pro when we declare(a,5). we are saying that a -> 5., as shown if we use the bindings. command.
If we say ?- add(a,5). then we will get true. in return.
If we want to look at what a is, bindings. then we will get back:
a -> 10.
a is now 10 instead of 5 because we replaced 5 with 10, this is the destructive part!


Nondestructive Operators in Arithmatic Equations

Key: These are called nondestructive because they create new global variable with the answer to the arithmatic equation.
Example:
In gv2.pro when we declare(a,10). and declare(b,5). we are saying that a -> 10. and b -> 5., as shown if we use the bindings. command.
If we say ?- add(a,b,sum). then we will get true. in return.
This differs from destructive because we are giving the equation a place to store the answer.
If we want to look at what a is, bindings. then we will get back:
a -> 10.
b -> 5.
sum -> 15.
a is still 10 instead of changing to another number because we save the answer into a new variable, this makes it non destructive!


Examples - Code and Demos

Global Variable GV1 - Destructive: View
Global Variable GV2 - Nondestructive: View