[mercury-users] Pred defns

Peter Schachte pets at students.cs.mu.OZ.AU
Tue Mar 31 17:11:40 AEST 1998


On Tue, 31 Mar 1998, Bart Demoen wrote:

> I guess he meant
>         main ::-
>                 print("Hello world\n"),
>                 $x := 42,
>                 $x := $x + 1,
>                 print("42 + 1 ="),
>                 print($x).

Oops.  Thanks, Bart.  Yes, that's what I *thought* I wrote.

Aside:  note that this basic approach works whether or not you want to allow
(or use) inter-predicate argument threading.  If you can use the $$ syntax
if you don't want it, and just drop the argument(s) if you do.

> The next step is not to require argument threading for implementing
> this; it has problems related to modules and higher-order.

I don't think the cross-module threading problem is much of problem:  just
require declarations of the "global variables" that are needed/defined by
exported predicates.  The rest can be inferred if you wish.

Higher-order uses are more of a problem, but, I think, one that can be
solved.

As to implementation approach, Fergus and I came up with a simple Mercury
extension that would allow the two approaches to be equivalent.  The basic
idea is to allow users to declare a "register" name, and then to associate
at most one register with each predicate argument.  This is a suggestion to
the compiler to pass that argument in some special location, rather than the
usual argument registers.  Of course, only one or two arguments to a given
predicate can be assigned the same register, and two only if the two
arguments have in and out (or di, uo, or mdi, muo) modes in all modes for
that predicate.  This avoids shuffling these things around in argument
registers.  It basically gives you the performance of the non-threading
approach without the (unnecessary) impurity of imperative global variables. 
Much nicer.


-Peter Schachte               | Mr. Spock succumbs to a powerful mating urge
mailto:pets at cs.mu.OZ.AU       | and nearly kills Captain Kirk. -- TV Guide,
http://www.cs.mu.oz.au/~pets/ | describing the Star Trek episode _Amok_Time_ 
PGP key available on request  | 




More information about the users mailing list