Source PostScript (apply.pps)

Retour Texte non formaté
%% syntaxe : [x1 ... xn] (f) apply --> [f(x1) ... f(xn)] /apply { 3 dict begin dup isstring {/fonction exch cvx def} {/fonction exch def} ifelse /liste exch def /@i 0 def [ liste length { liste @i get fonction /@i @i 1 add store } repeat counttomark 0 eq {pop} {]} ifelse end } def %% syntaxe : [x1 ... xn] (f) papply /papply { 3 dict begin dup isstring {/fonction exch cvx def} {/fonction exch def} ifelse /liste exch def /@i 0 def [ liste length 2 idiv { liste @i get liste @i 1 add get fonction /@i @i 2 add store } repeat counttomark 0 eq {pop} {]} ifelse end } def %% syntaxe : [x1 ... xn] (f) capply /capply { 3 dict begin dup isstring {/fonction exch cvx def} {/fonction exch def} ifelse /liste exch def /@i 0 def [ liste length 3 idiv { liste @i get liste @i 1 add get liste @i 2 add get fonction /@i @i 3 add store } repeat counttomark 0 eq {pop} {]} ifelse end } def %% syntaxe : [x1 ... xn] (f) dapply /dapply { 3 dict begin dup isstring {/fonction exch cvx def} {/fonction exch def} ifelse /liste exch def /@i 0 def [ liste length 4 idiv { liste @i get liste @i 1 add get liste @i 2 add get liste @i 3 add get fonction /@i @i 4 add store } repeat counttomark 0 eq {pop} {]} ifelse end } def %% syntaxe : [x1 ... xn] (f) n1 n2 Apply %% f prend n2 parametres, et on decale de n1 a chaque %% iteration. ainsi le 1er parametre de la 2eme iteration est x_(1+n1) /Apply { 6 dict begin /n2 exch def /n1 exch def dup isstring {/fonction exch cvx def} {/fonction exch def} ifelse /liste exch def /@i 0 def [ liste length n1 add n2 sub n1 idiv { /@j 0 def n2 { liste @i @j add get /@j @j 1 add store } repeat fonction /@i @i n1 add store } repeat counttomark 0 eq {pop} {]} ifelse end } def