I have a ps file with this line:
^ab {@st0 setfont}^ap
When ^ab
is defined here:
/^ab{1000 array 0 1000}bind def
and ^ap
is defined here:
/^ap{
dup length 3 index add dup 3 index lt{
4 index exch 6 2 roll exch
4 1 roll putinterval
}{
3 -1 roll 1000 add dup
{array}stopped{
pop pop pop
3 1 roll 0 exch getinterval
cvx bind
1000 array dup 0 4 -1 roll put
dup 1 /exec load put
2 1000 4 -1 roll ^ap
}{
dup 0 8 -1 roll putinterval
dup 6 -2 roll putinterval
3 1 roll
}ifelse
}ifelse
}bind def`
So if I'm reading it correctly, ^ab
creates on the stack an array of size 1000 and 2 integers: 0 and 1000.
Then the procedure {@st0 setfont}
is saved on the stack so the stack looks like this:
[array, 0, 1000, {@st0 setfont}]
Then ^ap
is called with dup
which duplicates the procedure on the stack and then length
is called which should get the length of the most top item on the stack which is the duplicated procedure, but it doesn't make sense to me. length
should be called only on a string, array or dictionary. So what's going on here?
Or am I interpreting it wrong?
A procedure is an array. Usually a packed array but that's not relevant. What happens here is that it gets the length of the array {@st0 setfont}
which is 2.
Try sticking a pstack
or dup ==
into the definition of the /^ap procedure, after the length.