1. currentdict

Returns the current dictionary (top of dictionary stack).

1.1. Syntax

– currentdict → dict

1.2. Stack Effects

Table 1. Before
Level Object

(none)

Table 2. After
Level Object

0

dict (current dictionary)

1.3. Description

currentdict pushes the current dictionary (the dictionary on top of the dictionary stack) onto the operand stack.

This does NOT pop the dictionary stack - it just pushes a duplicate reference to the top dictionary.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Getting current dictionary
currentdict  % Returns userdict (if no begin executed)
Checking current scope
5 dict begin
  currentdict  % Returns the 5-element dict
  /mykey known % Check if mykey in current dict
end
Adding to current dictionary
currentdict /newkey newvalue put
% Same as: /newkey newvalue def

1.6. Common Use Cases

1.6.1. Saving Current Dictionary

/savedict currentdict def
% ... operations that change dict stack ...
savedict begin
  % Restore dictionary context
end

1.6.2. Iterating Current Dictionary

currentdict {
  exch =  % Print key
  =       % Print value
} forall

1.6.3. Conditional Definitions

currentdict /setting known not {
  /setting defaultValue def
} if

1.7. Common Pitfalls

Does Not Pop Dictionary Stack - currentdict leaves dictionary stack unchanged.
dict begin
  currentdict  % Stack: dict (dict stack unchanged)
  % dict stack still has dict on it
end
Returns Reference - Modifying the returned dictionary affects the dictionary on the stack.
currentdict /key value put
% Modifies the dict on the dictionary stack
Use for Debugging - Examine current dictionary during development:
currentdict { exch = = } forall  % Print all entries

1.8. Error Conditions

Error Condition

[stackoverflow]

No room on operand stack

1.9. Implementation Notes

  • Very fast operation

  • Returns reference to actual dictionary (not a copy)

  • Standard use case for def is currentdict key value put

1.10. Typical Dictionary Stack

Top    → Local dict (via begin)
         ...
         userdict
         globaldict (Level 2)
Bottom → systemdict

currentdict returns the topmost dictionary.

1.11. See Also

  • begin - Push dictionary onto stack

  • end - Pop dictionary from stack

  • dictstack - Copy entire dict stack to array

  • countdictstack - Count dictionaries on stack

  • def - Define in current dictionary


Back to top

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