1. putinterval

Replaces a subsequence of an array or string with the contents of another array or string.

1.1. Syntax

array1 index array2 putinterval → –
array1 index packedarray2 putinterval → –
string1 index string2 putinterval → –

1.2. Stack Effects

Table 1. Before
Level Object

2

array1 or string1 (destination)

1

index (starting position)

0

array2, packedarray2, or string2 (source)

Table 2. After
Level Object

(empty)

Destination modified in place

1.3. Description

putinterval replaces a subsequence of the first operand starting at index with the entire contents of the third operand.

The objects are copied from the source to the destination as if by a sequence of individual get and put operations. For arrays, if copied elements are composite objects, their values are shared between source and destination.

Requirements: * index must be valid (0 to length-1) * index + length(source) must not exceed length(destination)

1.4. PostScript Level

Level 1 and later

1.5. Examples

Array replacement
/ar [5 8 2 7 3] def
ar 1 [(a) (b) (c)] putinterval
ar  % Now [5 (a) (b) (c) 3]
String replacement
/st (abc) def
st 1 (de) putinterval
st  % Now (ade)
Copying array segments
/src [10 20 30] def
/dest [0 0 0 0 0] def
dest 1 src putinterval
dest  % Now [0 10 20 30 0]

1.6. Common Use Cases

1.6.1. String Construction

/buffer 20 string def
buffer 0 (Hello, ) putinterval
buffer 7 (World!) putinterval
buffer 0 13 getinterval  % "Hello, World!"

1.6.2. Array Merging

/result 10 array def
result 0 [1 2 3] putinterval
result 3 [4 5 6] putinterval
% result[0..5] = [1 2 3 4 5 6]

1.6.3. Buffer Management

/buffer 100 string def
buffer position data putinterval
/position position data length add def

1.7. Common Pitfalls

Destination Must Be Large Enough - index + length(source) must not exceed destination length.
[1 2 3] 2 [4 5] putinterval  % Error: 2+2 > 3
Cannot Modify Packed Arrays - Packed arrays are read-only.
<array> 0 [1 2] putinterval  % Error if <array> is packed
Shared Composite Objects - When copying arrays containing composite objects, the values are shared.
/src [[1]] def
/dest [null] def
dest 0 src putinterval
dest 0 get 0 99 put  % Modifies BOTH arrays!
VM Restrictions - If destination is in global VM and source contains local VM objects, [invalidaccess] error occurs.
Efficient Copying - putinterval is more efficient than multiple put operations for bulk copying.

1.8. Error Conditions

Error Condition

[invalidaccess]

Destination in global VM contains local VM source, or destination is read-only

[rangecheck]

index + source length > destination length

[stackunderflow]

Fewer than 3 operands on stack

[typecheck]

Wrong operand types or type mismatch

1.9. Implementation Notes

  • Elements are copied, not moved

  • For composite array elements, references are copied (values shared)

  • Packed arrays can be source but not destination

  • String elements are copied by value (integers 0-255)

1.10. Performance Considerations

  • Much faster than individual put operations

  • Efficient for bulk array/string operations

  • No intermediate objects created

  • Memory bandwidth limited for large copies

1.11. See Also

  • getinterval - Extract subarray/substring

  • put - Store single element

  • get - Get single element

  • astore - Store stack into array


Back to top

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