Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3129

Re: Control Structures

Newsgroups comp.lang.postscript
Date 2017-06-28 10:57 -0700
References <2f65c3d3-60f0-48d6-af25-7af2964b9254@googlegroups.com> <20170623002801.61560cd4@samara.DOMA> <3c26cbff-0802-482a-a6d2-07b17781a1d4@googlegroups.com>
Message-ID <73236ae3-bc2c-4fea-b4a5-bf43bf4d9060@googlegroups.com> (permalink)
Subject Re: Control Structures
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


Rewrote it all again. This one uses binary tokens to construct a template
string that will parse quickly. I also re-wrote /reverse without a for loop.
No real advantage in doing that, I suppose. But fun practice.

The commented lines show "readable" postscript, then the encoded system
names in decimal (as I looked them up in PLRM Appendix F), then the
encodings in hex. Then there's a hex string which represents the same
code as the "readable" version.



%!
<<
    /curry        { [ 3 1 roll  {}forall ] cvx }
    /compose      { [ 3 1 roll  2 array astore  { {}forall }forall ] cvx }
    /reverse      { dup xcheck exch  [ exch  reverse-rest  ]  exch { cvx } if }
    /reverse-rest { dup length 0 gt {
                        dup rest /reverse-rest cvx 3 -1 roll /first cvx  4 array astore cvx exec
                    }{ pop } ifelse  }
    /first        { 0 get }
    /rest         { 1 1 index length 1 sub getinterval }
    /args-begin   { dup length dict begin { exch def } forall }
    /func         { exch reverse /args-begin load curry
                    exch compose { end } compose }
    /ps{pstack/ =}/pq{ps quit}
>> begin
%errordict/undefined{pstack} 3 copy pop get compose put                                                                                                                                                                           
%errordict/rangecheck{pstack} 3 copy pop get compose put                                                                                                                                                                          

/fortuple {a n p}{
    /# currentdict def
%({ end  0   //n    //a    length 1  sub  {  //a    exch //n    getinterval//p    exec }  for  //#    begin }) cvx exec                                                                                                           
%d  57   136 110    97     98        169            62          76                63      72          13                                                                                                                          
%x  39   88  6E     61     62        A9             3E          4C                3F      48          0D                                                                                                                          
<7b 9239 30  2f2f6e 2f2f61 9262   31 92a9 7b 2f2f61 923e 2f2f6e 924c       2f2f70 923f 7d 9248 2f2f23 920d  7d> cvx exec
    exec
} func def

[1 2 3 4] 2 {} fortuple
pq



$ gsnd -q struct.ps
[3 4]
[1 2]

Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Control Structures luser droog <luser.droog@gmail.com> - 2017-06-21 22:50 -0700
  Re: Control Structures Carlos <carlos@cvkm.cz> - 2017-06-23 00:28 +0200
    Re: Control Structures luser droog <luser.droog@gmail.com> - 2017-06-23 00:01 -0700
      Re: Control Structures luser droog <luser.droog@gmail.com> - 2017-06-28 10:57 -0700
        Re: Control Structures luser droog <luser.droog@gmail.com> - 2017-06-28 21:25 -0700
          Re: Control Structures luser droog <luser.droog@gmail.com> - 2017-06-30 03:05 -0700
            Re: Control Structures (Ordered Dictionaries) luser droog <luser.droog@gmail.com> - 2017-07-03 20:01 -0700
              Binding - Re: Control Structures (Ordered Dictionaries) Carlos <carlos@cvkm.cz> - 2017-07-04 17:21 +0200
                Type-checked function arguments - Re: Binding - Re: Control Structures (Ordered Dictionaries) luser droog <luser.droog@gmail.com> - 2017-07-09 10:44 -0700
                Re: Type-checked function arguments - Re: Binding - Re: Control Structures (Ordered Dictionaries) luser droog <luser.droog@gmail.com> - 2017-07-10 09:33 -0700
                Re: Type-checked function arguments - Re: Binding - Re: Control Structures (Ordered Dictionaries) luser droog <luser.droog@gmail.com> - 2017-07-15 20:00 -0700
                Re: Type-checked function arguments - Re: Binding - Re: Control Structures (Ordered Dictionaries) luser droog <luser.droog@gmail.com> - 2017-07-25 23:07 -0700
                Re: Type-checked function arguments - Re: Binding - Re: Control Structures (Ordered Dictionaries) Carlos <carlos@cvkm.cz> - 2017-07-26 16:41 +0200
                Re: Type-checked function arguments - Re: Binding - Re: Control Structures (Ordered Dictionaries) luser droog <luser.droog@gmail.com> - 2017-07-26 10:29 -0700

csiph-web