Article View: comp.lang.postscript
Article #2352A useful def for self-contained packages
From: Bernie Cosell
Date: Sun, 10 Jun 1990 12:46
Date: Sun, 10 Jun 1990 12:46
49 lines
2404 bytes
2404 bytes
Well, another round of debugging of bbfig uncovered a fairly subtle problem
when writing an independent library-like package that is intended to be
loaded with arbitrary other packages. We all know enough to put all of our
<def>'s in a private-to-the-module dictionary and be very careful to <begin>
that dictionary. Well, I just got through with an embarrassingly difficult
debugging of a problem with bbfig: that of getting systemdict things
redefined. I was trying to bbfig a small file that had the not-unreasonable
definitions:
/mt /moveto load def
/lt /lineto load def
innocent enough... but wait: "lt" is already defined as something else!!
Whoops... all of a sudden "a b lt { whatever } if" doesn't do quite the right
thing any more... Clearly a 'bind' when your package is first loaded is what
is necessary, but it is at best awkward, and in the limit impossible, simply
to have all of your <def>s turn into <bind def>s.
Well, the following is a snippet which I had buried in the trace
package I posted a while back, but this is a useful and necessary
enough function that I think it is worth calling out as a useful 'tool'
to have on its your in the standard bag of tricks. What you do is
write your file just as you normally would --- putting the <def>s
freely in any order you choose. But also include a <def> for this:
% key binddefinition - ; this will do a 'bind' on the procedure given by 'key'
/binddefinition
{
dup where
{
exch
2 copy
get bind put
}
{ undefined } ifelse
} def
Then, at the very end of your file, make the dict-stack be the way you want
it to be (typically this just means doing a "moduledict begin"), and put in a
sequence of
/firstdef binddefinition
/secondef binddefinition
...etc
and that'll fix everything so that your module is cleanly freed of the
randomnesses that the user might foist on you by the time your package gets
called.
/Bernie\
Technical Details
Message-ID:
<57234@bbn.BBN.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!snorkelwacker!mit-eddie!bbn.com!cosellShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!snorkelwacker!mit-eddie!bbn.com!cosell From: cosell@bbn.com (Bernie Cosell) Newsgroups: comp.lang.postscript Subject: A useful def for self-contained packages Message-ID: <57234@bbn.BBN.COM> Date: 10 Jun 90 12:46:16 GMT Sender: news@bbn.com Reply-To: cosell@BBN.COM (Bernie Cosell) Organization: BBN Systems and Technologies, Inc, Cambridge MA Lines: 49