1. dictstack
Copies all dictionaries from the dictionary stack into an array.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
0 |
|
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.5. Examples
countdictstack array dictstack
% Returns subarray with all dictionaries
10 array dictstack
{ dup /FontDirectory known { pop } { = } ifelse }
forall
/showDictStack {
countdictstack array dictstack
0 exch {
exch
(Dict ) print dup =only (\n) print
1 add
} forall
pop
} def
1.6. Common Use Cases
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 |
|---|---|
[ |
Dictionary on stack has no-access attribute |
[ |
Array too small for dictionary stack |
[ |
No operand on stack |
[ |
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
-
countdictstack- Get stack depth -
begin- Push dictionary -
end- Pop dictionary -
currentdict- Get current dictionary