Article View: comp.lang.postscript
Article #3784Re: A question about //add
From: Glenn Reid
Date: Fri, 23 Nov 1990 19:28
Date: Fri, 23 Nov 1990 19:28
48 lines
2421 bytes
2421 bytes
In article <21745@well.sf.ca.us> shiva@well.sf.ca.us (Kenneth Porter) writes:
>// is particularly useful for re-defining system operators in
>heavily nested situations:
>
>/showpage { stuff //showpage more-stuff } def
>
>The problem here is that one has to test for whether the system operator
>has be re-defined before; if so, then an exec has to be added after
>the name:
>
>/systemname load operatortype { /systemname { //systemname } def } if
This second bit of code doesn't work, for one thing; you need to use
the "type" operator:
/systemname load type /operatortype eq { ... } if
And for another thing, it's not a particularly good idea. You're
changing "systemname" from being an operator into being a procedure
that calls only a single operator, which is less efficient. You're
much better off with "bind" in your "showpage" example; it has the
same strengths (and weaknesses, in that you have to make sure
"showpage" hasn't already been redefined).
Heavily-nested situations don't affect "bind"; it is applied recursively
to all the procedures nested within the outermost procedure.
In general, // is more dangerous than "bind" or "load". The only situation
where I use it is if I have some constants that I want to define up front
in the program for readability (rather than hard-wiring them into the
code) but I don't want to suffer name lookup time whenever the constants
are used. As long as they're my own names, I don't have to worry about
their having been redefined. For example:
/leftmargin 72 def
/topmargin 792 72 sub def
/startpage {
//leftmargin //topmargin moveto
/Times-Roman 12 selectfont
} bind def
% Glenn
--
Glenn Reid RightBrain Software
glenn@heaven.woodside.ca.us PostScript/NeXT developers
..{adobe,next}!heaven!glenn 415-851-1785
Technical Details
Message-ID:
<329@heaven.woodside.ca.us>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!mit-eddie!snorkelwacker.mit.edu!apple!decwrl!adobe!heaven!glennReferences:
<1990Nov12.195235.13908@light.uucp> <321@heaven.woodside.ca.us> <1990Nov14.170020.16233@light.uucp> <21745@well.sf.ca.us>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!mit-eddie!snorkelwacker.mit.edu!apple!decwrl!adobe!heaven!glenn From: glenn@heaven.woodside.ca.us (Glenn Reid) Newsgroups: comp.lang.postscript Subject: Re: A question about //add Message-ID: <329@heaven.woodside.ca.us> Date: 23 Nov 90 19:28:11 GMT References: <1990Nov12.195235.13908@light.uucp> <321@heaven.woodside.ca.us> <1990Nov14.170020.16233@light.uucp> <21745@well.sf.ca.us> Reply-To: glenn@heaven.woodside.ca.us (Glenn Reid) Organization: RightBrain Software, Woodside, CA Lines: 48