Path: utzoo!attcan!uunet!midway!mimsy!brillig.cs.umd.edu!spector From: spector@brillig.cs.umd.edu (Lee Spector) Newsgroups: comp.sys.mac.hypercard Subject: Re: Trapping out Command-Period key presses. Message-ID: <26547@mimsy.umd.edu> Date: 14 Sep 90 13:52:47 GMT References: <10190@goofy.Apple.COM> <44774@apple.Apple.COM> Sender: news@mimsy.umd.edu Reply-To: spector@brillig.cs.umd.edu (Lee Spector) Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In article <44774@apple.Apple.COM> stadler@Apple.COM (Andy Stadler) writes: >... nayeri@cs.umass.edu writes: >>Steve, why can't command-period be an event and generate a message just like >>anything else? > >Sending "abort" messages wouldn't be very useful, because the only time you >could receive such a message is during idling -during which cmd-period doesn't >really do anything anyway. > >Command period is dangerous when it is pressed in the middle of a long script >or during some long operation. By the time you received the "abort" message >the long operation will have long since completed and it won't really be able >to do any good. > >--Andy stadler@apple.com I think there IS a good way to deal with aborts that preserves interruptability and also assures that important "cleanup" code always gets executed. As a LISP hacker I've become very fond of LISP's UNWIND-PROTECT special form. Unwind-protect takes a bunch of code to be executed (the "protected form" in lisp lingo) and some "cleanup" code (actually, any number of "cleanup forms"). Unwind-protect guarantees to execute the cleanup code before exiting, whether it terminates normally or is aborted (for more detail see Steele's Common Lisp: The Language, p.140). If you have some improtant stuff that must be executed, then you can put it in the cleanup code of an unwind-protect. [Now in LISP you can also abort from the cleanup code, and if you want to do something special in this case then you have to use ANOTHER unwind-protect...] Anyway, I find this very useful because whenever I write code that would cause nasty problems when interrupted, I just put it in an unwind-protect with cleanup code that takes care of things in some minimal way. How could this be done in HyperCard? I guess you could have a special handler AbortHandler which gets invoked immediately upon doing Command-. This handler should run in the binding environment active at the time of the abort (so you could restore things based on the values of local variables). You could use HC 2.0's cantAbort property within the handler if you wanted, though you'd better be careful. Syntactically, it would be nice to be able to define abort handlers in the normal way ("on myAbortHandler1 ...") and then to assign handlers to AbortHandler dynamically. (On entering a particular nasty loop you might want to say "put myAbortHandler1 into AbortHandler"). I hope this provides food for thought... -Lee (spector@cs.umd.edu)