Table of Contents
1. currentdict
Returns the current dictionary (top of dictionary stack).
1.2. Stack Effects
| Level | Object |
|---|---|
(none) |
| Level | Object |
|---|---|
0 |
|
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.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.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.9. Implementation Notes
-
Very fast operation
-
Returns reference to actual dictionary (not a copy)
-
Standard use case for
defiscurrentdict 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