%!PS % begin included library code % see https://codeberg.org/Firedrake/postscript-libraries/ /s2a { [ exch { } forall ] } bind def /test { /test.count test.count 1 add def { /test.pass test.pass 1 add def } { ( ) print test.count (....) cvs print (-fail) print } ifelse } bind def /strjoin % [(a) (b) (c)] (j) -> (ajbjc) { 3 dict begin /j exch def dup 0 get /out exch def /first true def { first { pop /first false def } { out j strconcat exch strconcat /out exch def } ifelse } forall out end } bind def /a2s { 2 dict begin /i exch def i length dup string /o exch def 1 sub 0 exch 1 exch { dup i 3 -1 roll get o 3 1 roll put } for o end } bind def /test.end { ( ) print test.count 0 gt { (Passed ) print test.pass (...) cvs print (/) print test.count (...) cvs print ( \() print test.pass 100 mul test.count idiv (...) cvs print (%\)) print (\r\n) print } if } bind def /test.start { print (:) print /test.pass 0 def /test.count 0 def } bind def /strconcat % (a) (b) -> (ab) { [ 3 -1 roll s2a aload length 2 add -1 roll s2a aload pop ] a2s } bind def /strsplit % (ajbjc) (j) -> [ (a) (b) (c) ] { 1 dict begin /sep exch def [ exch { dup length 0 eq { pop exit } { sep search { exch pop dup length 0 eq { pop } { exch } ifelse } { () } ifelse } ifelse } loop ] end } bind def % end included library code /replacewords { 0 dict begin exch /ww exch def [ exch ( ) strsplit { /w exch def /r false def ww { /lw exch def w lw anchorsearch { pop pop lw /r true def exit } { pop } ifelse } forall r not { w } if } forall ] ( ) strjoin end } bind def (replacewords) test.start [(cat) (bat) (rat)] (the cattle was rattle by the battery) replacewords (the cat was rat by the bat) eq test [(a) (b) (c)] (aab aac and cac bab) replacewords (a a a c b) eq test [(man) (bike)] (the manager was hit by a biker) replacewords (the man was hit by a bike) eq test test.end