1. end

Pops the current dictionary from the dictionary stack.

1.1. Syntax

– end → –

1.2. Stack Effects

Table 1. Before
Level Object

(none)

Dictionary stack has at least 3 dictionaries

Table 2. After
Level Object

(none)

Dictionary stack decreased by one

1.3. Description

end pops the current dictionary off the dictionary stack, making the dictionary below it the new current dictionary.

If end attempts to pop the bottommost instance of userdict, it executes [dictstackunderflow] error. The permanent dictionaries (systemdict, globaldict, userdict) cannot be removed.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Balanced begin/end
10 dict begin
  /x 100 def
end
% x no longer accessible
Nested scopes
dict1 begin
  /var1 1 def
  dict2 begin
    /var2 2 def
  end
  % var2 no longer accessible
  % var1 still accessible
end
% var1 no longer accessible
Error recovery
{
  mydict begin
  % ... operations that might fail ...
  end
} stopped {
  end  % Clean up dict stack on error
} if

1.6. Common Use Cases

1.6.1. Scoped Definitions

5 dict begin
  /temp 42 def
  % Use temp
  temp 2 mul
end
% temp no longer defined

1.6.2. Configuration Blocks

/config 20 dict def
config begin
  /setting1 value1 def
  /setting2 value2 def
end

1.7. Common Pitfalls

Unmatched end - Executing end without matching begin causes [dictstackunderflow].
end  % Error: no matching begin
Cannot Pop Permanent Dictionaries - Cannot pop systemdict or the bottommost userdict.
% After many ends...
end  % Eventually: dictstackunderflow
Use Defensive Coding - In error handlers, ensure dictionary stack is properly balanced.

1.8. Error Conditions

Error Condition

[dictstackunderflow]

Attempt to pop bottommost userdict, or stack already at minimum

1.9. Implementation Notes

  • Dictionary stack minimum: systemdict, userdict (Level 1)

  • Dictionary stack minimum: systemdict, globaldict, userdict (Level 2)

  • Very fast operation

  • Does not modify operand stack

1.10. Best Practices

Always balance begin/end
dict begin
  % ... operations ...
end  % Always match
Use in procedures
/myProc {
  10 dict begin
    % Local scope
  end
} def

1.11. See Also


Back to top

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