1. store

Stores a value in the dictionary stack (searches for existing key first).

1.1. Syntax

key value store → –

1.2. Stack Effects

Table 1. Before
Level Object

1

key

0

value

Table 2. After
Level Object

(empty)

Dictionary modified

1.3. Description

store searches for key in each dictionary on the dictionary stack, starting with the topmost (current) dictionary.

  • If found: replaces the value in that dictionary

  • If not found: creates new entry in current dictionary

This differs from def, which always uses the current dictionary.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Store vs. def
/x 1 def  % Define in current dict

5 dict begin
  /x 2 def     % New x in new dict
  /x 3 store   % Modifies x in current dict (now 3)
end

/x load  % Returns 1 (outer x unchanged)
Updating existing values
/counter 0 def
% ... later ...
/counter counter 1 add store  % Increment counter
Equivalent to def when not found
/newvar 42 store  % Same as /newvar 42 def (not found)

1.6. Common Use Cases

1.6.1. Global Variable Updates

/globalCounter 0 def

/increment {
  5 dict begin  % Local scope
    /globalCounter globalCounter 1 add store
  end
} def

1.6.2. Configuration Updates

% Update wherever it's defined
/setting newValue store

1.7. Common Pitfalls

Searches Dictionary Stack - store may modify a dictionary other than the current one!
/x 1 def  % In userdict

10 dict begin
  /x 99 store  % Modifies x in userdict, not current dict!
end
Global/Local VM Restrictions - Same VM rules as def apply.
Use def for New Definitions - Use def when you want to ensure definition goes in current dictionary.
Use store for Updates - Use store when you want to update an existing definition regardless of where it is.

1.8. Error Conditions

Error Condition

[dictfull]

Current dictionary full and key not found (Level 1)

[invalidaccess]

Global VM dict would receive local VM value

[limitcheck]

Dictionary expansion exceeds limits

[stackunderflow]

Fewer than 2 operands on stack

1.9. Implementation Notes

  • Equivalent to: key where { exch put } { currentdict exch put } ifelse

  • May trigger dictionary expansion in Level 2

  • Searches top-down through dictionary stack

  • Creates entry in current dict only if key not found

1.10. Comparison

Aspect def store

Target

Always current dictionary

First dict containing key, or current if not found

New keys

Current dictionary

Current dictionary

Existing keys

Current dictionary (shadows outer)

Dictionary where found (updates outer)

Use case

New definitions

Variable updates

1.11. See Also

  • def - Define in current dictionary

  • load - Load from dictionary stack

  • where - Find which dictionary contains key

  • put - Put into specific dictionary


Back to top

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