[mercury-users] Circular lists

Paul Massey pma at miscrit.be
Thu Nov 27 23:16:56 AEDT 1997


Just thought I'd comment on this ....

Fergus> Well, that's a fairly high price to pay.  If I have
Fergus> to choose between efficiency and safety, for a
Fergus> feature like the foreign language interface, I'd
Fergus> rather have efficiency.

Efficiency depends on the frequency of use of the functions
to be called. If it's called infrequently, I'd prefer to use
a mega-safe version, but if it's very frequently I'd prefer
the efficient version.

Fergus> What exactly do you mean by safely here? 

Here's an example with a silly error in it:

:- module t.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- import_module int.
:- import_module list.
:- import_module string.

main -->
	{ death(1,Out) },
	io__format("Do something = %d\n",[i(Out)]).

:- pred death(int::in,int::out) is det.
:- pragma(c_code, death(I::in,O::out),"{ int sp0; sp=I; O=sp0;}").

With this I get no warnings that I'm doing something
dangerous/stupid. My system just crashes at a later point
(all sorts of very unhelpful messages about
cygwin-exception-handler being called, etc, on my WinNT).

Given that the sp??? typo could be hidden in any piece of C
code (in my code, the library or elsewhere) it could take
alot of effort to find such a problem. So *my* programming
efficiency drops. For me, I'd say a safe ELI means that *my*
code being brain-dead or having typo's should not crash the
Mercury system in a place over which I don't have any

One of the things I liked about BIMProlog was that it had a
number of levels in the ELI facilities. The top level being
about as safe as its possible to get it (loads of checks,
copying, etc), with a second level providing 'pass'
parameters which had much of the protections removed (faster
but more dangerous - although never as dangerous as the

Having those multiple levels meant that I could use the
safer/slower functions in less critical/infrequently used
code and the faster/more dangerous code in the more critical
sections (where I more often spend the time trying to remove
redundant calls/debugging/testing/etc in any case). This at
least meant when a problem occured that I could reduce the
search space to those areas using the less-safe facilities.

Mercury has at present only the lower level interface (my
opinion). Wouldn't it be possible to add a higher-level
facility which provides more checking so that I can make the
above trade-off during my any development ?



More information about the users mailing list