2 protect - read or set protect status for a variable or named block
11 sts integer, 0 <= sts < 512
16 With one argument, protect(var) or protect(nblk) returns the current
17 protection status for var or nblk.
19 With two arguments, protect(var, sts) or protect(nblk, sts) sets the
20 protection status for var or nblk to the value sts. Each nonzero bit
21 of sts corresponds to one kind of protection as follows:
26 2 no change of value of var
27 4 no change of type of var
28 8 no error value for var
29 16 no copy to var or nblk
30 32 no relocation of var or nblk
32 128 no copy from var or nblk
33 256 protect recursively all components of var
36 Here "assign" refers to use of '=' as in A = expr to assign the value
37 of expr to A, and in A = {..., expr, ...} to assign the value of expr
38 to some component of A, and to the assignments implicit in swap(A, B),
39 quomod(x, y, A, B), and pre or post ++ or --.
41 For example, if A is a global variable, then after
45 an error state is established if A = expr is attempted. It does
46 not imply constancy if, for example, the current value of A is a list
47 or matrix; such a value may be changed by assignments to the elements
48 of A, or by push or copy commands.
50 If the current value of A is val, protect(A, 2) will prevent any
51 assignment to A other than
55 where expr evaluates to val.
57 Any such protection of A is cancelled by protect(A, 0).
59 If A has components as in a matrix or list, components may be
60 protected independently from each other and from A by stateents like:
65 "Copy" refers to the use of copy(A, B, ...) or blkcpy(B, A, ...) to
66 copy A to B. For example if B is a block, then after
70 attempts to copy to B will fail.
72 The protection status of var refers to var as a variable, not to its
73 current value: if an operation like var = value is executed it may
74 change the value of var but not protect(var).
76 A named block may be referred to by using the blocks() or blk()
77 functions, or by assigning it to a variable A and then using either
78 A or *A. In the latter cases, protect(A, sts) sets the status for
79 the variable A; protect(*A, sts) assigns the status for the named
80 block. For example, protect(*A,16) will prevent any copying to the
81 named block; protect(A,16) will prevent any copying to the named block
82 only when it is referred to by A.
84 The protection provided by sts = 32 prevents relocation of the memory
85 used by a block, the freeing of a named block, and addition or removal
86 of one or more elements from a list. For example, if a block B has
87 maxsize 256, then after
91 copy(A, B) will fail if the copying would cause size(B) to equal or
92 exceed 256; if B is a named block, blkfree(B) will not be permitted.
93 If the current value of L is a list, protect(L, 32) prevents the
94 execution of push, pop, append, remove, insert, and delete with first
97 With bit 8 of sts set, as with
101 the protection provided by the lower order bits extends to any
102 elements A may have, and recursively to any elements of these elements,
105 All protection of A as described above is removed by
116 No-assign-to destination for assign
120 Change of value in assign not permitted
126 Change of type in assign not permitted
130 Error value in assign not permitted
132 > A = mat[4] = {1,2,3,4}
138 "No-copy-to destination variable"
146 "No-relocation destination variable"
150 No-relocate list for push
154 No-assign-from source for assign
160 "No-copy-from source variable"
162 > mat A[2] = {1, list(2, mat[2])}
165 No-assign-to destination for assign
170 mat [2] (2 elements, 1 nonzero):
174 > A = blk("alpha") = {1,2,3,4}
179 No-copy-to destination named block