1. cvn

Converts a string to a name object.

1.1. Syntax

string cvn → name

1.2. Stack Effects

Table 1. Before
Level Object

0

string

Table 2. After
Level Object

0

name (lexically same as string)

1.3. Description

cvn (convert to name) converts the string operand to a name object that is lexically identical to the string.

The resulting name: * Has the same executable/literal attribute as the string * Is interned in the name table * Can be used as a dictionary key

1.4. PostScript Level

Level 1 and later

1.5. Examples

Basic conversion
(abc) cvn        % Result: /abc
Executable name
(abc) cvx cvn    % Result: abc (executable)
Dynamic name generation
(font) 10 20 string cvs
exch dup length string
dup 0 4 3 index putinterval
dup 4 3 index putinterval
cvn
% Result: /font10

1.6. Common Use Cases

1.6.1. Dynamic Dictionary Keys

/prefix (item) def
0 1 9 {
  20 string cvs
  prefix exch concatstrings
  cvn  % Convert to name for dict key
  % Use as dictionary key
} for

1.6.2. Configuration Loading

file readline {
  token { cvn } if  % Convert key to name
  token { exch def } if
} if

1.6.3. Computed Names

/basename (MyFont) def
/size 12 def
basename (-) size 20 string cvs
concatstrings cvn
% Result: /MyFont-12

1.7. Common Pitfalls

Name Length Limit - Names have implementation-dependent maximum length (typically 127 characters).
very-long-string cvn  % May cause limitcheck
Names Are Interned - All identical name objects share the same entry in the name table, consuming VM.
% Each unique name uses VM
1 1 1000 { 20 string cvs cvn pop } for
% Created 1000 names in VM
String Must Be Readable - String must not have no-access attribute.
Names vs. Strings as Keys - Names are more efficient as dictionary keys than strings.

1.8. Error Conditions

Error Condition

[invalidaccess]

String has no-access attribute

[limitcheck]

String exceeds maximum name length

[stackunderflow]

No operand on stack

[typecheck]

Operand is not a string

1.9. Implementation Notes

  • Names are stored in a global name table

  • Identical strings convert to the same name object

  • Name table consumes VM (cannot be freed)

  • Executable attribute preserved from string

1.10. Performance Considerations

  • Name creation involves hash table lookup

  • First occurrence of a name allocates VM

  • Subsequent conversions of same string return same name (fast)

  • Avoid creating many unique names unnecessarily

1.11. See Also

  • cvs - Convert to string

  • type - Get object type

  • cvlit - Make literal

  • cvx - Make executable


Back to top

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