Re: Assert_failure exception

From: Pierre Weis (weis@pauillac.inria.fr)
Date: Mon Dec 01 1997 - 11:17:25 MET


From: Pierre Weis <weis@pauillac.inria.fr>
Message-Id: <199712011017.LAA19058@pauillac.inria.fr>
Subject: Re: Assert_failure exception
In-Reply-To: <199712010149.UAA02524@cmpsci13.cs.umass.edu> from "Adam P. Jenkins" at "Nov 30, 97 08:49:51 pm"
To: ajenkins@cs.umass.edu (Adam P. Jenkins)
Date: Mon, 1 Dec 1997 11:17:25 +0100 (MET)

> Date: Sun, 30 Nov 1997 20:49:51 -0500
> From: "Adam P. Jenkins" <ajenkins@cs.umass.edu>
>
> I noticed that the Assert_failure exception is defined as
>
> exception Assert_failure of (string * int * int)
>
> but the arguments don't seem to be used for anything meaningful. More
> importantly, the "assert" statement gives no indication of where it
> was called from, or what expression it was called on.

The argument of exception Assert_failure is used to report the file
name and the characters that bound the assert statement in the file.

> Since assert
> seems to be a language level statement, it could actually set the
> string argument of Assert_failure to a string representation of the
> asserted expression when it fails.
>
> Now:
>
> # assert (1 = 2);;
> Uncaught exception: Assert_failure(_)
>
> What I'd like to see:
>
> # assert (1 = 2);;
> Uncaught exception: Assert_failure("1 = 2")
>
> Do you plan to add anything like this? For me, the fact that the
> Assert_failure exception gives me no indication of where it was raised
> makes me unlikely to use the assert statement.
>
> Sorry I can't post in French.
>
> Adam

There should be a small ``misfeature'' in the toplevel interactive
system that does not report properly the location of the assertion. If
you use the compiler, you get

lat: ~: cat tmp.ml
assert ( 1 = 2 );;
lat: ~: ocamlc tmp.ml
lat: ~: a.out
Fatal error: uncaught exception Assert_failure("tmp.ml", 0, 16)

That's what you expected, no ?

The modification you suggested could be interesting, although it seems
to me to be strictly less powerful than the actual implementation of
assert (assuming the toplevel misfeature be corrected).

All the best,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:13 MET