On Thursday, August 29, 2013 2:51:01 AM UTC-5, luser- -droog wrote:
> Clean-ed up a bit, with some brief exposition.
Optimized up a bit. Replaced linear-lookup error handler
with a constructed dictionary.
%!
%
abbr.ps
% abbreviated system names
% exports (defines) 1 procedure:
% - ABBR dict
% which generates an abbreviation dictionary.
%
% This allows you to use alphabetic abbreviations for
% standard systemdict names, suxh as:
%
% a %= abs
% ad %= add
% mu %= mul
% pr %= print
% g %= ge
% f %= file
% etc. Check PLRM 2ed or 3ed, Appendix F Encoded System Names
/ABBR {
2 dict begin
225 -1 0 { % generate defs in reverse alphabetic (numeric) order
%dup =only( )=only
<910> dup 1 4 3 roll put cvx exec
%dup =only( )=only
cvx dup =string cvs % op str
%pstack()= stop
exch
dup { currentdict end exch load
} stopped { pop begin cvlit }{ exch begin exch pop } ifelse
exch
%pstack() = %stop
0
1 1 3 index length
%1 sub
{ % opname str 0 i
3 copy getinterval % opname str 0 i str[0,i]
%dup =only( )=only
cvn 4 index def
pop % opname str 0
} for
%()=
pop pop pop
} for
0 1 225 { % print out the shortest ABBR name for each system name.
dup =only( )=only
<910> dup 1 4 3 roll put cvx exec % opname
dup =only( )=only
cvx dup =string cvs
exch
dup { currentdict end exch load
} stopped { pop begin cvlit }{ exch begin exch pop } ifelse
exch
0
{
1 1 3 index length 1 sub {
3 copy getinterval
dup cvn load % opname str 0 i str[0,i] loaded
5 index eq {
=only( )=only
pop
stop
}{
pop pop
} ifelse
} for
} stopped pop
()=
pop pop pop
} for
/ABBR where pop /ABBR currentdict put %memo
currentdict end
} bind def
currentfile flushfile % comment-out this line to test
ABBR begin
2 3 ad
4 mu
=string cvs pr
(\n)pr % prints "20"
end
ABBR begin
%!
%Sierpinski Triangle via L-system
<</F{F - G + F + G - F}/G{G G}>>b
{F - G - G}7{[ex{du w{ex get al po}if}fora]}rep
cvx<</F{3 0 rl}/G 1 in/-{120 rot}/+{-120 rot}>>b
100 200 mov exe fill showp
end