1. type
Returns a name identifying the type of an object.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
0 |
|
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.5. Type Names
| Object Type | Returned Name |
|---|---|
Array |
|
Boolean |
|
Dictionary |
|
File |
|
Font (fontID) |
|
Graphics state |
|
Integer |
|
Lock (DPS) |
|
Mark |
|
Name |
|
Null |
|
Operator |
|
Packed array |
|
Real |
|
Save object |
|
String |
|
Condition (DPS) |
|
1.6. Examples
123 type % Result: integertype
3.14 type % Result: realtype
(text) type % Result: stringtype
/name type % Result: nametype
[1 2 3] type % Result: arraytype
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
[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.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.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