next up previous index
Next: Visibility Up: Arrays and Global Previous: Arrays

Global References

  Terms stored in normal arrays are copies of setval/2 arguments, and the terms obtained by getval/2 are thus not identical to the original terms, in particular their variables are different. Sometimes it is more convenient or even necessary to be able to access the original term with its variables, i.e. to have global variables in the meaning of conventional programming languages. A typical example is the use of graphical interface: if we want to modify the value of a Prolog variable through a graphical user interface, this mechanism has to be used because the user interface has no means to access Prolog terms directly. Another example are interrupt handlers - they normally cannot access Prolog variables from the interrupted execution, but sometimes this is necessary.

ECLiPSe offers the possibility to store nonground terms and to access them even inside predicates that have no common variables with the predicate that has stored them. They are stored in global variables of special type global_reference. For example,

make_array(p, global_reference)
creates a global variable p which can be used to store global references to terms. This global variable is accessed and modified in the usual way, with setval/2 and getval/2, but there are differences to normal arrays: .

There is only a limited number of global references available and their use should be considered very carefully. Their misuse can lead to very bad programs which are inefficient, difficult to understand and difficult to optimize.



next up previous index
Next: Visibility Up: Arrays and Global Previous: Arrays



Micha Meier
Mon Mar 4 12:11:45 MET 1996