1. type

Returns a name identifying the type of an object.

1.1. Syntax

any type → name

1.2. Stack Effects

Table 1. Before
Level Object

0

any (any object)

Table 2. After
Level Object

0

name (executable name identifying type)

1.3. Description

type returns a name object that identifies the type of its operand. The returned name has the executable attribute, making it convenient for type-dependent processing via dictionary lookup.

1.4. PostScript Level

Level 1 and later

1.5. Type Names

Object Type Returned Name

Array

arraytype

Boolean

booleantype

Dictionary

dicttype

File

filetype

Font (fontID)

fonttype

Graphics state

gstatetype

Integer

integertype

Lock (DPS)

locktype

Mark

marktype

Name

nametype

Null

nulltype

Operator

operatortype

Packed array

packedarraytype

Real

realtype

Save object

savetype

String

stringtype

Condition (DPS)

conditiontype

1.6. Examples

Basic type checking
123 type         % Result: integertype
3.14 type        % Result: realtype
(text) type      % Result: stringtype
/name type       % Result: nametype
[1 2 3] type     % Result: arraytype
Type-dependent processing
5 dict begin
  /integertype { (Integer: ) print = } def
  /realtype { (Real: ) print = } def
  /stringtype { (String: ) print = } def

  42 dup type exec      % Prints "Integer: 42"
  3.14 dup type exec    % Prints "Real: 3.14"
end
Distinguishing arrays
[1 2 3] type /arraytype eq        % true
1 2 3 3 packedarray type /packedarraytype eq  % true

1.7. Common Use Cases

1.7.1. Type Validation

/validateNumber {
  dup type dup
  /integertype eq
  exch /realtype eq or not {
    /typecheck cvx exec
  } if
} def

1.7.2. Generic Processing

/typeHandlers 10 dict def
typeHandlers /integertype { handle-int } put
typeHandlers /stringtype { handle-str } put

/process {
  dup type typeHandlers exch get exec
} def

1.7.3. Debugging

/showtype {
  dup type 20 string cvs print
  ( : ) print =
} def

123 showtype         % Prints "integertype : 123"

1.8. Common Pitfalls

Font vs. Dictionary - A font dictionary returns dicttype, not fonttype. Only fontID objects return fonttype.
/Helvetica findfont type  % dicttype
Executable Name - The returned name is executable, which affects how it’s processed.
123 type          % Pushes executable 'integertype'
% If executed, looks up in dictionary
Future Types - The set of types may expand in future PostScript versions. Handle unknown types gracefully.

1.9. Error Conditions

Error Condition

[stackunderflow]

No operand on stack

1.10. Implementation Notes

  • Very fast operation (type stored with object)

  • Returns executable name for dictionary-based dispatch

  • Type names defined in systemdict

  • Useful for polymorphic operators

1.11. Type Hierarchy

PostScript has no formal inheritance, but types can be categorized:

  • Simple types: integer, real, boolean, null, mark

  • Composite types: array, packedarray, string, dictionary

  • Reference types: name, operator, save, gstate, font, file

  • Synchronization (DPS): lock, condition

1.12. See Also

  • cvlit - Convert to literal

  • cvx - Convert to executable

  • xcheck - Test if executable

  • rcheck - Test if readable

  • wcheck - Test if writable


Back to top

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