1. get

Retrieves a single element from an array, packed array, dictionary, or string.

1.1. Syntax

array index get → any
packedarray index get → any
dict key get → any
string index get → int

1.2. Stack Effects

Table 1. Array/String Access
Level Object

1

array, packedarray, or string

0

index (integer 0 to n-1)

Table 2. Result
Level Object

0

Element at index (or character code for strings)

Table 3. Dictionary Access
Level Object

1

dict

0

key

Table 4. Result
Level Object

0

Value associated with key

1.3. Description

get retrieves a single element from a composite object:

  • For arrays and packed arrays: returns the element at the specified index

  • For strings: returns the integer character code (0-255) at the specified index

  • For dictionaries: returns the value associated with the specified key

Indices for arrays and strings are 0-based: valid range is 0 to length-1.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Array element access
[31 41 59] 0 get        % Returns 31
[31 41 59] 2 get        % Returns 59
Mixed-type array
[0 (a mixed array) [ ] { add }] 1 get
% Returns (a mixed array)
String character access
(abc) 1 get             % Returns 98 (ASCII 'b')
(a) 0 get               % Returns 97 (ASCII 'a')
Dictionary lookup
/mydict 5 dict def
mydict /mykey (myvalue) put
mydict /mykey get       % Returns (myvalue)

1.6. Common Use Cases

1.6.1. Coordinate Extraction

/point [100 200] def
point 0 get  % x coordinate: 100
point 1 get  % y coordinate: 200

1.6.2. Character Code Processing

(Hello) 0 get 32 sub  % Convert 'H' to lowercase offset

1.6.3. Configuration Lookup

configdict /PageSize get  % Get page size setting

1.7. Common Pitfalls

String Returns Integer - get on a string returns an integer (character code), not a one-character string.
(abc) 0 get  % Returns 97, not (a)
Index Range - Index must be in range 0 to length-1. Out-of-bounds access causes [rangecheck] error.
[1 2 3] 3 get  % Error: valid indices are 0-2
Dictionary Key Not Found - If the key doesn’t exist in a dictionary, [undefined] error occurs.
5 dict /nokey get  % Error: key not in dictionary
Use known/where First - For dictionaries, use where or known to check if a key exists before using get.

1.8. Error Conditions

Error Condition

[invalidaccess]

Object has no-access or execute-only attribute

[rangecheck]

Index out of bounds for array/string

[stackunderflow]

Fewer than 2 operands on stack

[typecheck]

First operand wrong type, or index not integer

[undefined]

Key not found in dictionary

1.9. Implementation Notes

  • For arrays and dictionaries, returns the actual object (not a copy)

  • For strings, returns a new integer object

  • Accessing composite elements creates no new objects (shares references)

  • Dictionary lookup is typically O(1) average case

1.10. Performance Considerations

  • Direct array indexing is very fast

  • String character access is equally fast

  • Dictionary lookup slightly slower but still efficient

  • For sequential access, forall may be more efficient than repeated get calls

1.11. See Also

  • put - Store value in array/string/dictionary

  • getinterval - Get subarray or substring

  • length - Get length of array/string

  • aload - Load all array elements

  • forall - Iterate over elements


Back to top

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