caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Ian T Zimmerman <itz@transbay.net>, caml-list@inria.fr
Subject: Re: Catching Break?
Date: Thu, 28 Jan 1999 12:14:11 +0100	[thread overview]
Message-ID: <19990128121411.00837@pauillac.inria.fr> (raw)
In-Reply-To: <199901260646.WAA13077@kronstadt.transbay.net>; from Ian T Zimmerman on Mon, Jan 25, 1999 at 10:46:13PM -0800

> 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




  reply	other threads:[~1999-01-28 12:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-25 18:43 Ian T Zimmerman
1999-01-26  0:24 ` Xavier Leroy
1999-01-26  6:46   ` Ian T Zimmerman
1999-01-28 11:14     ` Xavier Leroy [this message]
1999-01-28 17:33       ` Ian T Zimmerman
1999-02-06  8:24         ` Ian T Zimmerman
1999-02-09  7:02           ` Ian T Zimmerman
1999-02-10 15:48             ` Xavier Leroy
1999-02-05 18:00   ` Ian T Zimmerman
1999-02-08 17:16     ` Xavier Leroy
1999-01-26  5:17 Frank A. Christoph
1999-01-26 11:23 Toby Moth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19990128121411.00837@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=itz@transbay.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).