1. put

Stores a value into an array, dictionary, or string element.

1.1. Syntax

array index any put → –
dict key any put → –
string index int put → –

1.2. Stack Effects

Table 1. Array/String Modification
Level Object

2

array or string

1

index (integer)

0

any (value to store)

Table 2. Dictionary Modification
Level Object

2

dict

1

key

0

any (value to store)

Table 3. After (all forms)
Level Object

(empty)

Composite object modified in place

1.3. Description

put replaces a single element in a composite object:

  • For arrays: stores any at position index (0 to n-1)

  • For strings: stores integer int (0-255) at position index

  • For dictionaries: associates any with key (creates new entry if key doesn’t exist)

The composite object is modified in place. If the array or dictionary value is in global VM and any is in local VM, an [invalidaccess] error occurs.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Array element modification
/ar [5 17 3 8] def
ar 2 (abcd) put
ar  % Now [5 17 (abcd) 8]
Dictionary entry creation
/d 5 dict def
d /abc 123 put
d { } forall  % Shows /abc 123
String modification
/st (abc) def
st 0 65 put      % 65 is ASCII 'A'
st               % Now (Abc)
Coordinate update
/point [100 200] def
point 0 150 put  % Change x to 150
point            % Now [150 200]

1.6. Common Use Cases

1.6.1. Array Element Updates

/colors [/red /green /blue] def
colors 1 /yellow put  % Replace green with yellow

1.6.2. Dictionary Configuration

/config 10 dict def
config /FontSize 12 put
config /FontName /Helvetica put

1.6.3. String Character Replacement

(hello) dup 0 72 put  % Change 'h' to 'H': (Hello)

1.7. Common Pitfalls

String Values Must Be Integers - Strings store character codes (0-255), not character strings.
(abc) 0 (X) put   % Error: must be integer
(abc) 0 88 put    % Correct: 88 is ASCII 'X'
Index Range - Array/string index must be 0 to length-1.
[1 2 3] 3 99 put  % Error: index 3 out of range
Packed Arrays are Read-Only - Cannot use put on packed arrays.
currentpacking true setpacking
{ 1 2 3 } 0 99 put  % Error: packed array
Dictionary Size (Level 1) - In Level 1, if dictionary is full, [dictfull] error occurs.
Dictionary Auto-Expands (Level 2) - In Level 2, dictionaries automatically expand when needed.

1.8. Error Conditions

Error Condition

[dictfull]

Dictionary full (Level 1 only)

[invalidaccess]

Object in global VM contains local VM value, or object is read-only

[rangecheck]

Index out of bounds, or int not in 0-255 for strings

[stackunderflow]

Fewer than 3 operands on stack

[typecheck]

Wrong operand types

1.9. Implementation Notes

  • Modifies the object in place (does not create a copy)

  • For composite values (arrays, dicts), stores by reference

  • Dictionary lookup to check for existing key

  • In Level 2, dictionaries grow automatically when needed

1.10. Performance Considerations

  • Array and string put are very fast (direct indexing)

  • Dictionary put slightly slower (hash table operation)

  • Repeated dictionary puts in Level 1 may trigger slow rehashing if dictionary grows full

  • For bulk updates, consider putinterval

1.11. See Also

  • get - Get element from array/string/dictionary

  • putinterval - Put subarray/substring

  • astore - Store multiple elements into array

  • length - Get length of array/string


Back to top

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