Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1199

Re: Popping dict leaves 0 on stack

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.postscript
Subject Re: Popping dict leaves 0 on stack
Organization Decebal Computing
References <87pq1vidu3.fsf@Compaq.site.inet>
Date 2012-12-27 21:20 +0100
Message-ID <87licji6wv.fsf@Compaq.site.inet> (permalink)

Show all headers | View raw


Op donderdag 27 dec 2012 18:50 CET schreef Cecil Westerhof:

> When I execute the following (with p2pdf):
> 5 dict begin
> end
>
> There is an extra zero on the stack. Because of that, I now use the
> following code:
> 5 dict begin
> end pop
>
> Is this an error in ps2pdf?

It is a little bizarre. Sometimes it is necessary and sometimes not.
And sometimes it depends on if another end put something on the stack.

I have the following function:
    /centerString { % msg [gray] x y
        4 dict begin
            /y   exch def
            /x   exch def
            dup type /integertype eq {
                /gray exch def
            } {
                /gray -1 def
            } ifelse
            /msg exch def

            x y moveto
            msg stringwidth pop -2 div
            0 % optional: textheight -2 div
            rmoveto
            msg gray doShow
    (3 centerString) ==
    pstack
        end
    (leave centerString) ==
    pstack
    } def

When another function put something on the stack with the end of a
dict, the same value is put on the stack after the end. But when I put
myself something on the stack, this does not happen. I'll try to make
a short script to demonstrate it.

This function seems to always leave something on the stack after the
end, so I put a pop into it:
    /rectangle { % left bottom right top
        4 dict begin
            /top    exch def
            /right  exch def
            /bottom exch def
            /left   exch def

            left  bottom moveto
            right bottom lineto
            right top    lineto
            left  top    lineto
            left  bottom lineto
            closepath
        end pop
    } def

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Popping dict leaves 0 on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-12-27 18:50 +0100
  Re: Popping dict leaves 0 on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-12-27 21:20 +0100
  Re: Popping dict leaves 0 on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-12-27 22:29 +0100

csiph-web