Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Aleksej Saushev Newsgroups: comp.lang.forth Subject: Re: Quotations revisited Date: Mon, 23 Jul 2012 03:29:31 +0400 Organization: A noiseless patient Spider Lines: 56 Message-ID: <87vchfml2c.fsf@inbox.ru> References: <00808889968435@frunobulax.edu> <2012Jul17.085127@mips.complang.tuwien.ac.at> <2012Jul17.094834@mips.complang.tuwien.ac.at> <0b-dnV4aqvPZvJjNnZ2dnUVZ_s-dnZ2d@supernews.com> <2012Jul17.124835@mips.complang.tuwien.ac.at> <2012Jul19.181131@mips.complang.tuwien.ac.at> <87liiet9be.fsf@inbox.ru> <30fdf529-6c73-49d7-8fdc-f02271e33ebc@g5g2000yqg.googlegroups.com> <--idnS0grfwsMZbNnZ2dnUVZ_qednZ2d@supernews.com> <871uk3r9vk.fsf@inbox.ru> <7vydnY5PU6bD3pHNnZ2dnUVZ_sSdnZ2d@supernews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="b3ce569266230e786ee0c639f44c9d1e"; logging-data="15808"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2R7UdOPW2Qnk54udgX5Vz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (berkeley-unix) Cancel-Lock: sha1:F9y4p6LP0z8vAA1xdmGmxJEl1ck= sha1:6n2Fa0vElNUfk8xsJxiiTwH2qF4= Xref: csiph.com comp.lang.forth:14290 "Elizabeth D. Rather" writes: > On 7/22/12 7:19 AM, Aleksej Saushev wrote: >> "Elizabeth D. Rather" writes: >> >>> On 7/21/12 12:59 AM, Alex McDonald wrote: >>>> On Jul 21, 3:20 am, "Elizabeth D. Rather" wrote: >>>>> On 7/20/12 11:24 AM, Aleksej Saushev wrote: >>> ... >>>>>>> Most implementations of DUMP I know of are interruptible but not >>>>>>> by trapping H. A more appropriate strategy is with a KEY? in the >>>>>>> loop, maybe once/line. Likewise anything else capable of >>>>>>> generating a lot of output. >>>>> >>>>>> Do you mean that there're no other ways to interrupt program than by >>>>>> writing it so that it constantly polls for some event? >>>>> >>>>> It's the cleanest to implement and has fewest side-effects. The cost of >>>>> a KEY? per line out output is pretty minimal, a lot less than a CATCH >>>>> around every H. >>>> >>>> In many hosted Forths, the executed instruction cost of KEY? per line >>>> will be much higher than a CATCH per H.; a call to the OS, context >>>> switching and stream management at the cost of several thousand >>>> instructions per KEY? is not minimal. >>> >>> In my experience, a keystroke is captured by an interrupt which >>> records the keyboard event. It does not take either an I/O >>> operation nor an OS call to inquire whether an event has >>> occurred, merely a check of a memory location. Thereupon code >>> can obtain the key if it cares, but often you're just interested >>> in the existence of the event. Very cheap. >> >> Not at all! You have to write the polling code everywhere you know >> it can be interrupted. You need to track all those places too. >> With "catch" you write all that code only once. Now compare the price. > > No, a keyboard interrupt handler is a single instance of code > that responds to an event. It doesn't poll. You have to check the result of this in any place where user (not you!) might interrupt the program. That is you have to poll it constantly. This is way more overhead than putting single "catch" around the top level. > And putting CATCH around something as tiny as H. implies you > have to sprinkle them in every word that does output. Ugh. No, it doesn't. If you have read my example, you have seen that it implies exactly the opposite: when I need to put single "catch" around top level word, you have to sprinkle your "key? if ... then" everywhere. Otherwise your code has to run till the end of lengthy loop only to find out that user asked to interrupt it perhaps several hours ago. -- HE CE3OH...