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


Groups > comp.lang.postscript > #1546

Re: Checking the stack is empty at the end of the program

Path csiph.com!usenet.pasdenom.info!aioe.org!rt.uk.eu.org!feed.xsnews.nl!border-3.ams.xsnews.nl!post-feeder-02.xsnews.nl!frontend-F09-08.ams.news.kpn.nl
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.postscript
Subject Re: Checking the stack is empty at the end of the program
Organization Decebal Computing
References <874nba9xyd.fsf@Aspire.decebal.nl> <kpKdnZ6ZmNZFJmTMnZ2dnUVZ_qWdnZ2d@earthlink.com> <cfac3023-1d88-463d-ae51-927c3f9cfa36@googlegroups.com>
X-Face "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E
X-Homepage http://www.decebal.nl/
Date Thu, 01 Aug 2013 10:41:29 +0200
Message-ID <87txj9951i.fsf@Aspire.decebal.nl> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)
Cancel-Lock sha1:vN3QMLEc+H0SddktnlI0WRaZmIQ=
MIME-Version 1.0
Content-Type text/plain
Lines 89
NNTP-Posting-Host 77.171.42.144
X-Trace 1375346737 news.kpn.nl 2822 77.171.42.144@kpn/77.171.42.144:53346
Xref csiph.com comp.lang.postscript:1546

Show key headers only | View raw


Op donderdag 1 aug 2013 08:53 CEST schreef luser:

> On Wednesday, July 31, 2013 8:36:55 PM UTC-5, Dan Coby wrote:
>> On 7/31/2013 3:16 PM, Cecil Westerhof wrote:
>>
>>> I would like to check that the stack is empty when a program is
>>
>>> finished. For this I made the following function:
>>
>>> /endProgram {
>>
>>> (end program) ==
>>
>>> pstack
>>
>>> (there should be nothing between (end program) en this line) ==
>>
>>> } def
>>
>>>
>>
>>> But this displays:
>>
>>> (end program)
>>
>>> (there should be nothing between \(end program\) en this line)
>>
>>>
>>
>>> It is not a very big problem, but could I display:
>>
>>> (end program)
>>
>>> (there should be nothing between (end program) en this line)
>>
>>>
>>
>>
>>
>> The 'count' operator returns the number of items on the stack.
>>
>> See page 550 of the PRLM 3rd.
>
> I agree with Dan here. Using the count operator you can do sthg like
>
> count {
> (Unexpected object on stack: ) print
> ==
> } repeat
>
> which does nothing if the stack is empty.

Good idea, I amended it a little:
    % to be called at the end of a program
    % if stack empty (as it should be) say this
    % otherwise signal this and show the stack
    % ends the program to circumvent/signal it being called to soon
    /endProgram {
        count 0 eq {
            (Stack empty at end of program) ==
            quit
        } {
            count dup
            1 eq {
                (ERROR: object on stack at the end of the program)   ==
            } {
                (ERROR: objects on stack at the end of the program)  ==
            } ifelse
            {
                (Unexpected object on stack: ) print
                ==
            } repeat
            quit
        } ifelse
        (This message should never be shown)       ==
        (If it is, the quit operater is overruled) ==
    } def

In this way I see that endProgram is executed. Also when quit is
overruled it is signalled.

Only one thing is missing. When the stack is not empty, I want to
signal an error. In this way the calling script will terminate. Is
this possible?

-- 
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

Checking the stack is empty at the end of the program Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 00:16 +0200
  Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-07-31 15:41 -0700
    Re: Checking the stack is empty at the end of the program Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 02:36 +0200
  Re: Checking the stack is empty at the end of the program Dan Coby <adcoby@earthlink.net> - 2013-07-31 18:36 -0700
    Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-07-31 23:53 -0700
      Re: Checking the stack is empty at the end of the program Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 10:41 +0200
        Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-08-01 02:37 -0700
          Re: Checking the stack is empty at the end of the program Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 12:40 +0200
            Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-08-01 03:53 -0700
              Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-08-01 03:56 -0700
                Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-08-01 04:23 -0700
                Re: Checking the stack is empty at the end of the program Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 15:45 +0200
              Re: Checking the stack is empty at the end of the program Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 13:18 +0200
                Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-08-01 09:33 -0700
                Re: Checking the stack is empty at the end of the program luser- -droog <mijoryx@yahoo.com> - 2013-08-01 18:25 -0700

csiph-web