[ ECLiPSe Arrays and Global Variables built-in.|Group Index| Full Index]

setval(+ElemSpec, ?Value)

Sets visible array element or global variable ElemSpec to the value Value.

+ElemSpec
Atom (global variable) or fully instantiated compound term with positive integer arguments (array element specification).
?Value
Prolog term.

Description

If ElemSpec is an atom, the value of the visible global variable ElemSpec is set to the Prolog term Value. If there was no global variable visible from the caller module, a global ``global variable'' (i.e. visible from all modules where no local ``global variable'' is defined with make_local_array/1) is created and its value is set to the Prolog term Value. The value of a global variable can be overwritten any number of times with any data type, including a free variable.

If ElemSpec is a compound term, it must specify a visible array element: all its argument must be non negative integers smaller that the bounds specified with make_array/1/2 or make_local_array/1/2.

If Element is a global reference, its value will be restored on backtracking. Otherwise, its value is destructively set to Value; on backtracking the old value is not restored.

If the array has been created with make_array(Array, Type) or make_local_array(Array, Type), then Value is restricted to the type Type; otherwise Value can have any type, including a free variable. Its value can be overwritten any number of time.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
ElemSpec is not ground
(4) Instantiation fault
ElemSpec is of an array of type integer, real or byte and Value is uninstantiated
(5) Type error
the type of Value is not of the declared type of ElemSpec.
(5) Type error
ElemSpec is a structure whose arguments are not all integers.
(5) Type error
ElemSpec is neither an atom nor a ground structure.
(6) Range error
Array index in ElemSpec is out of bounds. Error 41 --- ElemSpec is an element of an array which does not exist.

Examples

   % In the following examples, make_array(a(4))
   % and make_array(b(4), real) have been called.
Success:
      make_array(a(4,3)),
          setval(a(0,0), 2),
          setval(a(1,2), "string"),
          % overwrite a(0,0) (= 2) with a free variable
          setval(a(0,0), X).
      make_array(a(4), real),
          setval(a(0), 2.0),
          setval(a(3), -19.6).
      setval(i, 4).
      setval(j, 4),
           setval(j, "string data").

Error:
      setval(A, 2.0).            (Error 4).
      setval(a(V), 2.0).         (Error 4).
      setval(a(1.0), 2).         (Error 5).
      setval("b(0)", 2.0).       (Error 5).
      make_array(a(4)),
          setval(a(-2), 2).      (Error 6).
      make_array(a(9), integer)
          setval(a(9), 4).       (Error 6).
      setval(no_array(1), 2.0).  (Error 41).


See Also

decval / 1, erase_array / 1, incval / 1, make_array / 1, make_array / 2, make_local_array / 1, make_local_array / 2, getval / 2