🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #996

Re: Building A PostScript Toolset

#996
From: Glenn Reid
Date: Fri, 01 Sep 1989 22:19
73 lines
2612 bytes
In article <1989Aug30.184607.21647@agate.uucp> labc-1aa@web.Berkeley.edu (Bob Heiney) writes:
>
>In order to minimize potential side effects, when you define names in a
>ToolSet procedure, you should put them in their own dictionary. 
>Start with a "n dict begin" where "n" is the number of locals you'll use, and
>finish with an "end".
>
>Example:
>
>/MyProcedure 		% arg1 arg2 MyProcedure result
>{
>  2 dict begin
>  /arg2 exch def /arg1 exch def
>
>  ...
>
>  end
>} def

It is a good idea to keep names local if you can.  Unfortunately,
your example isn't good because it creates a new dictionary every time
you call the procedure, which is probably not what you want.

Here are three ways to get the local dictionary without paying for it
each time you call the procedure.  The first is nice but won't
work on a version 23.0 LaserWriter (which was discontinued in 1986
or something like that, when the LaserWriter Plus came out).  The
second one will work on all implementations, but you have to do
a name lookup on the dictionary every time you call the procedure.
The last one is the least intrusive (no extra names defined) the
most efficient, and the hardest to understand :-)

% version 1:
/localdict 2 dict def
/MyProcedure 		% arg1 arg2 MyProcedure result
{
	//localdict begin
		/ arg2 exch def / arg1 exch def
		...
		end
} def

% version 2:
/localdict 2 dict def
/MyProcedure 		% arg1 arg2 MyProcedure result
{
  localdict begin
	/arg2 exch def /arg1 exch def
	...
  end
} def

/MyProcedure 		% arg1 arg2 MyProcedure result
{
  REPLACEME begin
	/arg2 exch def /arg1 exch def
	...
  end
}
dup	% dup the procedure body
0	% the 0'th element is the REPLACEME name
2 dict	% you want a dictionary of 2 elements there
put	% put 2 dict into slot 0 of procedure body (array)
def	% /MyProcedure {...} def


As a final footnote, if you have many procedures that are always
together, there is no real need to have separate dictionaries
for each one.  You could define a single name like $mydict that's
big enough for all of them, then start each proc with //$mydict begin.

Glenn Reid
Adobe Systems
Technical Details
Message-ID: <1139@adobe.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!decwrl!adobe!greid
References: <1989Aug30.184607.21647@agate.uucp>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!decwrl!adobe!greid
From: greid@adobe.com (Glenn Reid)
Newsgroups: comp.lang.postscript
Subject: Re: Building A PostScript Toolset
Message-ID: <1139@adobe.UUCP>
Date: 1 Sep 89 22:19:13 GMT
References: <1989Aug30.184607.21647@agate.uucp>
Sender: news@adobe.COM
Reply-To: greid@adobe.COM (Glenn Reid)
Organization: Adobe Systems Incorporated, Mountain View
Lines: 73