[comp.lang.postscript] Blue book #19 confustion

marmar@mtk.UUCP (Mark Martino) (11/16/89)

I was studying example #19 in the blue book today and I came across a
line that I don't understand.  The program runs so it must make sense to
the interpreter, but it doesn't make sense to me.

When creating a new font dictionary, this example uses this line:

{ exch newfont 3 1 roll put }

"newfont" appears to be a new empty dictionary. I don't understand how
newfont is being accessed and used here.  If one enters a string without
the "/", the interpreter trys to find it in the dictionaries.  Shouldn't this
return some kind of "can't find" error?  It seems to do this if you set
this up and try to run it by itself.

I really need to understand this so I can create some new fonts for
myself.  Would someone please explain in more detail what is going on
here?  Thanks for the reality.

woody@rpp386.cactus.org (Woodrow Baker) (11/17/89)

In article <932@mtk.UUCP>, marmar@mtk.UUCP (Mark Martino) writes:
> I was studying example #19 in the blue book today and I came across a
> line that I don't understand.  The program runs so it must make sense to
> the interpreter, but it doesn't make sense to me.
> 
> When creating a new font dictionary, this example uses this line:
> 
> { exch newfont 3 1 roll put }

Recall that the put operator installs an item into an array, dictionary, string
etc.  newfont is indeed a new dictionary.  Also recall that there is a font
dictionary on the stack just before this, so we have
1
3
newfont dict
old font dict
Now, the roll operator changes the order of the stack such that the
put operator takes the old font dict, and sticks it into the new font dict.
It simply is making a copy of the old font dict, and the new font dict
has had a bit of space added to it such that we have a spot to put a new
id etc in.

cheers, Woody

> 
> "newfont" appears to be a new empty dictionary. I don't understand how
> newfont is being accessed and used here.  If one enters a string without
> the "/", the interpreter trys to find it in the dictionaries.  Shouldn't this
> return some kind of "can't find" error?  It seems to do this if you set
> this up and try to run it by itself.
> 
> I really need to understand this so I can create some new fonts for
> myself.  Would someone please explain in more detail what is going on
> here?  Thanks for the reality.

rsilverman@eagle.wesleyan.edu (11/18/89)

In article <932@mtk.UUCP>, marmar@mtk.UUCP (Mark Martino) writes:
> I was studying example #19 in the blue book today and I came across a
> line that I don't understand.  The program runs so it must make sense to
> the interpreter, but it doesn't make sense to me.
> 
> When creating a new font dictionary, this example uses this line:
> 
> { exch newfont 3 1 roll put }
> 
> "newfont" appears to be a new empty dictionary. I don't understand how
> newfont is being accessed and used here.  If one enters a string without
> the "/", the interpreter trys to find it in the dictionaries.  Shouldn't this
> return some kind of "can't find" error?  It seems to do this if you set
> this up and try to run it by itself.

If you look just four lines earlier in the code, you find

	/newfont numentries dict def

which creates a new dictionary via the "dict" operator and binds it to the name
"newfont".  Does this answer your question?
						Richard Silverman