Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!execu!sequoia!rpp386!woody From: woody@rpp386.cactus.org (Woodrow Baker) Newsgroups: comp.lang.postscript Subject: Re: Postscript idiot needed help (and got it) Summary: extremely good advice. Message-ID: <17903@rpp386.cactus.org> Date: 11 Feb 90 01:43:40 GMT References: <4017@hydra.Helsinki.FI> <17807@rpp386.cactus.org> <8260@shlump.nac.dec.com> Organization: River Parishes Programming, Plano, TX Lines: 63 In article <8260@shlump.nac.dec.com>, batcheldern@hannah.enet.dec.com (Ned Batchelder) writes: > I recommend reading the Green Book, not to be indoctrinated into one > particular method of writing procedures, but to get exposed to other > ideas on the matter. code deleted> > Notice that I also rearranged the arguments to reduce stack manipulations. > This is a very good general technique for reducing time and complexity. > If you look on page 75 of the Red Book (at least my edition), there is a > figure explaining the non-zero winding rule that gives an idea: > > % rin rout x y `donut' -- > > /donut { > gsave > translate > 0 0 3 -1 roll 0 360 arc > 0 0 3 -1 roll 0 360 arcn > fill > grestore > } bind def > > This avoids all of the setgray's, and makes a real donut, in that things > will show through the "hole". It also does only one "fill", which will > will help on the speed. > A point about "local" variables: They're not local. If your program gets > more complex, with procedures invoking other procedures, and each saves > arguments in variables, you may find yourself having to worry about name > clashes. All of the variables get stored in the same dictionary (unless > you use a separate dict for each proc, another headache). This is also a > huge hassle if you want to write recursive procedures, as you then need > a separate dictionary for each invocation of the same procedure. Boy, isn't that the truth! One of the reasons that I avoid recursion like the plague. Recursion also total obscures what is going on. Even in 'C'. You might, if you are going to try recursion, try creating dynamic dictionaries by creating a new dictionary name and copying the old one into it before executing the recurse. I'm not even sure that would work, but you can do it, as far as I know. I've never tried it. I don't think I want to. I would be inclined to simulate my own stack..... t E > And finally, if you use variables in your procedure, and bind the > procedure, you can get into a lot of trouble when being included into > other PostScript. Another topic for a longer posting. > > I recommend that you learn how to write procedures so that they need a > minimum of stack manipulation, and then avoid the variables. Your code > will be shorter and faster. Verily, Verily, hear ye! It might be less maintainable, but definitly shorter and faster. m Cheers> Woody