1. wcheck

Tests whether an object’s access attribute permits writing to its value.

1.1. Syntax

array wcheck → bool
dict wcheck → bool
file wcheck → bool
string wcheck → bool

1.2. Stack Effects

Table 1. Before
Level Object

0

Composite object

Table 2. After
Level Object

0

bool (true if writable, false otherwise)

1.3. Description

wcheck tests whether the operand’s access attribute permits its value to be written (modified) by PostScript operators.

Returns: * true if access is unlimited * false if access is readonly, executeonly, or noaccess

1.4. PostScript Level

Level 1 and later

1.5. Examples

Writable objects
[1 2 3] wcheck          % true (unlimited access)
3 dict wcheck           % true (can add entries)
(text) wcheck           % true (can modify)
Non-writable objects
[1 2 3] readonly wcheck    % false
{ code } wcheck            % false (procedures readonly by default)
Packed arrays
1 2 3 3 packedarray wcheck  % false (always readonly)
File objects
(file.ps) (w) file wcheck  % true (write mode)
(file.ps) (r) file wcheck  % false (read mode)

1.6. Common Use Cases

1.6.1. Safe Modification

/safe-put {
  3 copy pop exch pop  % array array index
  wcheck {
    put
  } {
    pop pop pop
    /invalidaccess cvx exec
  } ifelse
} def

1.6.2. Validation Before Write

array wcheck not {
  /invalidaccess cvx exec
} if
array index value put

1.6.3. Permission Checking

dict wcheck {
  dict /key value put
} {
  (Dictionary is read-only) print
} ifelse

1.7. Common Pitfalls

Packed Arrays Always Read-Only - Packed arrays created with packedarray always return false for wcheck.
1 2 3 3 packedarray wcheck  % false
Readonly is Permanent - Once an object is made readonly, it cannot be made writable again.
[1 2 3] readonly
% No way to restore unlimited access
Confusing wcheck with xcheck - wcheck tests write access, xcheck tests executable attribute.
Check Before Modifying - Use wcheck before operations like put or putinterval on untrusted objects.

1.8. Error Conditions

Error Condition

[stackunderflow]

No operand on stack

[typecheck]

Operand not array, dict, file, or string

1.9. Access Attribute Hierarchy

Attribute Set By Can Write?

Unlimited

(default for most objects)

Yes

Readonly

readonly

No

Executeonly

executeonly

No

Noaccess

noaccess

No

1.10. Implementation Notes

  • Fast operation (checks access bits)

  • Does not modify the object

  • Packed arrays inherently readonly

  • Simple objects (numbers, booleans) have no access attribute

1.11. Common Patterns

Conditional modification
object wcheck {
  % Modify object
} {
  % Create writable copy
  object dup length array copy
  % Modify copy
} ifelse

1.12. See Also

  • rcheck - Test if readable

  • xcheck - Test if executable

  • Access operators: readonly, executeonly, noaccess

  • put - Modify array/string/dict

  • type - Get object type


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.