1. dictstack

Copies all dictionaries from the dictionary stack into an array.

1.1. Syntax

array dictstack → subarray

1.2. Stack Effects

Table 1. Before
Level Object

0

array (must be large enough)

Table 2. After
Level Object

0

subarray (portion of array used)

1.3. Description

dictstack stores all elements of the dictionary stack into array and returns an object describing the initial n-element subarray, where n is the current depth of the dictionary stack.

Dictionaries are copied in order: * Element 0 ← bottommost dictionary (systemdict) * Element n-1 ← topmost dictionary (current)

The dictionary stack itself is unchanged.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Capturing dictionary stack
countdictstack array dictstack
% Returns subarray with all dictionaries
Examining stack contents
10 array dictstack
{ dup /FontDirectory known { pop } { = } ifelse }
forall
Debugging dictionary context
/showDictStack {
  countdictstack array dictstack
  0 exch {
    exch
    (Dict ) print dup =only (\n) print
    1 add
  } forall
  pop
} def

1.6. Common Use Cases

1.6.1. State Inspection

% Save dictionary stack state
/savedStack countdictstack array dictstack def
% ... operations ...
% Compare with current
countdictstack array dictstack
% Check if same

1.6.2. Error Reporting

errordict /handleerror {
  $error begin
    (Error in context:\n) print
    countdictstack array dictstack
    { = } forall
  end
} put

1.7. Common Pitfalls

Array Must Be Large Enough - If array length < dictionary stack depth, [rangecheck] error occurs.
2 array dictstack  % Error if dict stack depth > 2
Returns Subarray - Result may be smaller than input array.
10 array dictstack
% Returns subarray of actual length, not full 10 elements
Use countdictstack - Allocate array of correct size:
countdictstack array dictstack  % Always correct size

1.8. Error Conditions

Error Condition

[invalidaccess]

Dictionary on stack has no-access attribute

[rangecheck]

Array too small for dictionary stack

[stackunderflow]

No operand on stack

[typecheck]

Operand is not an array

1.9. Implementation Notes

  • Copies dictionary references (not the dictionaries themselves)

  • Very fast operation

  • Useful for debugging and state management

  • Result shares dictionary objects with stack

1.10. See Also


Back to top

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