2009/11/18

PostScript 高階手続き

 

%!PS-Adobe-3.0
% P.35 2.11 高階手続き
% higher order procedure

/twice {
    1 dict begin
        /proc exch def
        proc proc
    end
} def

{ (KPF) == } twice % (KPF)(KPF)

/sum {
    2 dict begin
        /f exch def
        /n exch def
        n 1 eq {
            1 f
        } {
            n 2 ge {
                n f
                n 1 sub
                /f load
                sum add
            } {
                (undefined)
            } ifelse
        } ifelse
    end
} def

10 { } sum == % 55
10 { dup mul } sum == % 385
10 { dup dup mul mul }  sum == % 3025

0 件のコメント:

コメントを投稿