From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA02007 for caml-redistribution; Thu, 28 Jan 1999 13:24:17 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA20007 for ; Thu, 28 Jan 1999 12:14:15 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id MAA16836; Thu, 28 Jan 1999 12:14:11 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA11855; Thu, 28 Jan 1999 12:14:11 +0100 (MET) Message-ID: <19990128121411.00837@pauillac.inria.fr> Date: Thu, 28 Jan 1999 12:14:11 +0100 From: Xavier Leroy To: Ian T Zimmerman , caml-list@inria.fr Subject: Re: Catching Break? References: <19990126012435.21454@pauillac.inria.fr> <199901260646.WAA13077@kronstadt.transbay.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <199901260646.WAA13077@kronstadt.transbay.net>; from Ian T Zimmerman on Mon, Jan 25, 1999 at 10:46:13PM -0800 Sender: weis > When I have read your mail I thought this would be trivial to work > around. But it isn't. First it isn't that obvious what counts as > a function application. Given the functional nature of ML I'd like to > say "everything". But then I start to have doubts. What about basic > arithmetic operators for instance? These do not check for signals. Worse, applications of primitive functions (defined by an "external" clause) don't check either. So, yes, it's kind of hard to know when signals will be tested exactly. > Finally, and more seriously, this is just a toy example. In my real > program, I need to return a _value_ from the expression that > corresponds to suicide(). I tried > > let suicide() = > begin Unix.kill (Unix.getpid()) Sys.sigint; 1 end > > let id x = x > > let suicidal = try > (suicide(), id 0) > with Sys.break -> (0, 0) First of all, that should be Sys.Break (an exception constructor), not Sys.break. It doesn't work because of the right-to-left evaluation order (id 0 is evaluated before suicide()). > let suicidal = try > id (suicide()) > with Sys.break -> 0 Works fine here (with Sys.Break of course). > Do I really have to use _sequencing_ to force a `safe point'? Not at all. > That > throws away the value from suicide(), so I'll have to invent a > reference to assign to - eeek! A sequencing operator that doesn't throw away the value of its left subexpression exists: it's called "let". One more comment: rather than sending yourself a signal, then turn the signal into an exception via the signal handler (as Sys.catch_break does), why not throw the exception directly? E.g. just raise Sys.Break when your program wishes to commit suicide. Exceptions are much nicer for synchronous notification; signals are a pain and only required for asynchronous notification (such as the user pressing ctrl-C). All the best, - Xavier Leroy