hascall@atanasoff.cs.iastate.edu (John Hascall) (11/23/89)
A while back, some interesting postscript procedures were posted by Clayton E. Cramer prompting a reply by Glenn Reid (of Adobe) regarding ways to define procedures so as to encapsulate dictionary entries (efficiently). Anyway, here is a modification (improvement?) of their ideas: John Hascall / ISU Comp Ctr. / Ames, IA %! %! define the procedure defining procedure :-) %! /PROC { % % /NAME { #locals begin .... end } PROC - % dup % /NAME {#...} {#...} dup % /NAME {#...} {#...} {#...} 0 get % /NAME {#...} {#...} #locals 0 exch % /NAME {#...} {#...} 0 #locals dict % /NAME {#...} {#...} 0 <dictionary with room for #locals> put % /NAME {D...} bind % /NAME {D...} def % } bind def %! %! Now define a procedure to do pie chart slices as an example %! /PieSlice { % % CENTERx CENTERy ANGLE0 ANGLE1 RADIUS GRAY LINEWIDTH PieSlice - % 7 begin /Width exch def /Gray exch def /Radius exch def /Angle1 exch def /Angle0 exch def /Y exch def /X exch def gsave newpath X Y moveto currentpoint Radius Angle0 Angle1 arc closepath Width setlinewidth Gray setgray fill grestore end } PROC %! %! make a pie with 5 slices %! 300 300 45 75 200 0.00 2 PieSlice 300 300 120 45 200 0.15 2 PieSlice 300 300 165 90 200 0.30 2 PieSlice 300 300 255 105 200 0.45 2 PieSlice 300 300 0 45 200 0.60 2 PieSlice %! %! show the page %! showpage
moore@RIGEL.FAC.CS.CMU.EDU (Dale Moore) (11/28/89)
John Hascall recently posted the following tool
/PROC {
%
% /NAME { #locals begin .... end } PROC -
%
dup % /NAME {#...} {#...}
dup % /NAME {#...} {#...} {#...}
0 get % /NAME {#...} {#...} #locals
0 exch % /NAME {#...} {#...} 0 #locals
dict % /NAME {#...} {#...} 0 <dictionary with room for #locals>
put % /NAME {D...}
bind % /NAME {D...}
def %
} bind def
Although it is a good tool for most applications, the problem
I see is that the resulting procedure is non-reentrant.
The procedure can not be recursive. The local variables are not
allocated on a stack. The space for the local variables is allocated
statically at procedure definition time.
This difference is alot like the difference between Fortran and
other languages like Algol, Pascal or C.
Dale Moore