% n sumints (sum(n)) /sumints { % straightforward recursive def % note how the stack eventually has n+1 items on it dup 0 eq {} {dup 1 sub sumints add} ifelse } def /sumints { % named parameter % now the *dict* stack has n+1 dictionaries on it 1 dict begin /i exch def i 0 eq {0} {i 1 sub sumints i add} ifelse end } def /sumints { % accumulating parameter % uses constant stack space 1 dict begin /sumints2 { % sumsofar ntogo sumints2 (sumsofar + (sum (ntogo)) dup 0 eq {pop} % 0 on stack from dup; answer is below it { dup 3 1 roll add exch 1 sub sumints2 } ifelse } def 0 exch sumints2 end } def