2
votes

Maybe a strange question, not sure if it makes sense or if I'm not yet at the correct learning point to understand it correctly.

In PostScript you have the CVN operator.

(abc) cvn => /abc
(abc) cvx cvn => abc

Now a name beginning with a slash is a literal name and a name without a slash is an exectuable name (not talking about any immediately evaluated names).

If you test these two lines in GhostScript this output is correct as expected. But what I really want to know is, is the output what you see just the Display value (= the .ToString()) value that you see. or is the '/' slash also being stored in the name value?

For example is the object being stored as (pseudo code):

new Name {
  theName = "abc";
  isLiteral = true;
}
return ToString() { 
if (isLiteral)
 return "/abc";
//..

or rather as:

new Name {
  theName = "/abc";
}
return ToString() {
  return theName;
}
2

2 Answers

2
votes

A name is merely a sequence of characters, as defined in the PLRM on page 54. Details of storage are irrelevant.

Its possible to store a string as just the characters, along with some associated data to define it as a name object and not, say, a string object. Or you could store the string with the characters and the preceding '\', so you know its a name.

Whether its literal or executable is a separate attribute.

I believe that all the implementations I'm aware of store the characters of the name without the preceding '/', and separately maintain data determining its type and attributes. Usually that's because they maintain a 'common' data type from which all other data types are derived.

But there's nothing that says you have to do it that way, and really you shouldn't care how the interpreter actually stores objects, provided its behaviour follows the specification.

The difference between an executable and literal is really to do with execution. If I do:

/Test

then I create a literal name which is then pushed on to the operand stack (because that's what we do with all literals). However if I do:

Test

Then I create an executable name, and execute it.

See section 3.5.5 on page 50 of the PLRM "Execution of specific types"

2
votes

Names are almost the same as strings but are designed to be faster to compare. So the stored value in a name object will usually be a hash value or pointer into a cache of strings associated with names.

You can browse the xpost implementation of type operators here
or functions common to all objects here
or implementation of names using ternary search tree and stack of strings.