GOLF! abbreviated system names

41 views
Skip to first unread message

luser- -droog

unread,
Aug 28, 2013, 3:23:08 AM8/28/13
to
Any undefined names are checked with anchorsearch
against the alphabetical encoded-system-name table.
First prefix match gets returned, and executed if
executable.
a = abs
ad = add
mu = mul
pr = print
g = ge
f = file



/names
[ 0 1 225 { <910> dup 1 4 3 roll put cvx exec } for ]
def

/match {
dup length string cvs
{
names {
dup dup length string cvs
2 index anchorsearch {
pop pop exch pop stop
} if
pop pop
} forall
} stopped not {
/unregistered signalerror
} if
} def

/abbr {
errordict/undefined{
dup xcheck exch match
exch { cvx exec } if
}put
} def

%2 3 /ad match pstack

abbr
2 3 ad
4 mu
=string cvs pr

luser- -droog

unread,
Aug 28, 2013, 3:55:41 AM8/28/13
to
On Wednesday, August 28, 2013 2:23:08 AM UTC-5, luser- -droog wrote:
> Any undefined names are checked with anchorsearch
> against the alphabetical encoded-system-name table.
> First prefix match gets returned, and executed if
> executable.
>
> a = abs
> ad = add
> mu = mul
> pr = print
> g = ge
> f = file
>

Consolidated and optimized (a little).
Works with "load" undefined errors as well as executable.


/matchbuf 50 string def

/abbr {
errordict/undefined{
dup type/operatortype eq{pop}if
dup xcheck exch
dup length string cvs
{
0 1 225 {
<910> dup 1 4 3 roll put cvx exec
dup //matchbuf cvs
2 index anchorsearch {
pop pop exch pop stop
} if
pop pop
} for
} stopped not {
/unregistered signalerror
} if
exch { cvx exec } if
}put
} def

abbr
2 3 ad
4 mu
=string cvs pr
(\n)pr % prints "20"

/ad load = % prints "/add"

luser- -droog

unread,
Aug 29, 2013, 3:51:01 AM8/29/13
to
Clean-ed up a bit, with some brief exposition.

%!
%abbr.ps
% abbreviated system names
% exports (defines) 1 procedure:
% ABBR
% which installs a replacement handler for the
% /undefined error that is raise when a name-lookup fails.
%
% Any undefined names are checked with anchorsearch
% against the alphabetical encoded-system-name table.
% First prefix match gets returned, and executed if
% executable. Failure in this search raises an
% /unregistered error.
%
% 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

1 dict begin
/matchbuf 50 string def

/ABBR {
errordict/undefined{
dup type/operatortype eq{pop}if
dup xcheck exch
dup length string cvs
{
0 1 225 {
<910> dup 1 4 3 roll put cvx exec
dup //matchbuf cvs
2 index anchorsearch {
pop pop exch pop stop
} if
pop pop
} for
} stopped not {
/unregistered signalerror
} if
exch { cvx exec } if
}put
}
end
def


currentfile flushfile % comment-out this line to test

ABBR
2 3 ad
4 mu
=string cvs pr
(\n)pr % prints "20"

/ad load == % prints "/add"


luser- -droog

unread,
Nov 15, 2013, 12:16:47 PM11/15/13
to
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
Reply all
Reply to author
Forward
0 new messages