Article View: comp.lang.postscript
Article #8915Re: Postscript idiot needed help (and got it)
From: Markku Pihlaja
Date: Thu, 08 Feb 1990 07:40
Date: Thu, 08 Feb 1990 07:40
59 lines
3301 bytes
3301 bytes
Jeff (bevis@EE.ECN.PURDUE.EDU) in article 2630:
> How should I construct the donut procedure to avoid having to save all the
> arguments in variables? Is that my only hope?
Woody (woody@rpp386.cactus.org) in article 2643:
> There is another philosophy
>that says, leave them on the stack, but to me it is more difficult to debug
>that way.
...
>I don't have my red book handy, so am not going to take the time to write
>the stack rotations and duplications, but you can work that out.
I've got mine handy, and since you definitely get more time-efficient code by
not using variables, I'll work it out here.
/donut { % Stack when calling: x y rin rout
0 setgray
3 index % x y rin rout x
3 index % x y rin rout x y
3 -1 roll % x y rin x y rout
0 360 arc fill % x y rin
1 setgray % x y rin
0 360 arc fill % -
0 setgray
} bind def
% Sorry, Woody, but I prefer the Glenn-style indentations
There are two points to look at here.
A lot of time is `wasted' when you have to load a value from a dictionary
(that's what happens when the interpreter encounters a token like `rad1').
Having 3 stack operations instead of 12 dictionary operations is no doubt
more effective.
Note also the `bind def' at the end. From the Red Book: `For each element
of proc that is an executable name, bind looks up the name in the context
of the current dictionary stack (as if by load). If the name is found and
its value is an operator object, bind replaces the name by the operator
in proc.' I.e. instead of executing `setgray' or `index' or `roll', which
means first loading the actual operator object from systemdict or wherever
it's defined and only after that executing it, bind replaces the names
by the operators already when defining the procedure. And if I've got it
right, in the example this means as much as 10 dictionary operations less
than without bind. Correct me if I'm wrong.
I agree with Woody, using variables usually does make the code more
readable. But if Jeff happens to need dillions of donuts drawn on one
page, then it is definitely better to use only stack manipulations instead
of variables.
Markku
====================================== =======================
Markku Pihlaja Please tell me if my
University of Helsinki, Finland English is not perfect.
pihlaja@cs.helsinki.fi I'm a perfectionist.
====================================== =======================
Technical Details
Message-ID:
<4017@hydra.Helsinki.FI>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!sunic!tut!hydra!pihlajaReferences:
<17807@rpp386.cactus.org> <9002040147.AA16999@en.ecn.purdue.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!sunic!tut!hydra!pihlaja From: pihlaja@cs.Helsinki.FI (Markku Pihlaja) Newsgroups: comp.lang.postscript Subject: Re: Postscript idiot needed help (and got it) Message-ID: <4017@hydra.Helsinki.FI> Date: 8 Feb 90 07:40:44 GMT References: <17807@rpp386.cactus.org> <9002040147.AA16999@en.ecn.purdue.edu> Organization: University of Helsinki, Department of Computer Science Lines: 59