[mercury-users] Pred defns

Peter Schachte pets at students.cs.mu.OZ.AU
Fri Mar 27 11:47:02 AEDT 1998


On Thu, 26 Mar 1998, Ralph Becket wrote:

> I've got the Prolog for a syntactic expansion that I find *very*
> helpful indeed, and much easier to read.
> 
> The idea is that X` denotes the `next state' of X and X`` expands to
> the extra pair of arguments X, X`.  For example:
> 
> 	io__write(..., IO``),		io__write(..., IO0, IO1),
> 	io__write(..., IO``),	 |->	io__write(..., IO1, IO2),
> 	io__write(..., IO``),		io__write(..., IO2, IO3),
> 
> and
> 
> 	X` = X + 1		 |->	X1 = X0 + 1

This does look like a nice extention.

I have a small complaints about it, though.  I am bothered by the fact
that the (apparent) arity of a call is different than the arity of the
definition.  I'd like to see some special syntax for clause heads as
well, so that the argument pairs that will be written as one V``
argument in calls will be written as one argument in the head.
Perhaps just making V`` in clause heads do the "right thing" would do
it.

<pause>

Ok, I can resist it no longer.  I'm going to take this opportunity for
shameless self-promotion.  I've written a similar package for Prolog
that goes a bit further, and tries to solve some related problems that
stem from having predicates with high arities.  These are:

    1.  When comparing a call to the predicate it calls, it is
	difficult to line up arguments to be sure that, say, the Map
	argument in the call corresponds to the Map argument in the
	clause head.  Worse, it may be that the Map argument in the
	clause head may correspond to the Table (or M or whatever)
	argument in the call.  I want the correspondence between (the
	names for) terms in different clauses in a program to be
	manifest.

    2.  Often in maintenance one must thread new bundles of arguments
	through many predicates, or remove no-longer-needed bundles.
	This is very time consuming, error-prone drudgery I'd like to
	avoid altogether.

    3.  I'd like to be able to "hide" more than just one argument of
	each thread pair.  I sometimes want to hide a single argument
	that is passed as input through many predicates to reach the
	one or two that need it.  Similarly for outputs that have to
	work their way back from deep in the call hierarchy.  I'd also
	sometimes like to hide both variables of an input/output pair.

    4.  I'd like to do all this with a simple mental model and without
	too much weird notation or a lot of declarations or runtime
	overhead.

It turns out that backtrackably reassignable global variables provide
all this.  The idea is that you assign a value to a variable at one
point in your program, and can read that value at any point after
that, until it is reassigned.  The other thing that is needed is a
scoping construct that allows you to temporarily (re)assign a value to a
variable for a certain chunk of code, and have it automatically revert
to the previous value when that scope is exited.

It's really pretty simple and intuitive.  It does, of course, mean
that conjunction isn't commutitive, but then conjunction has never
been commutitive in Prolog anyway.

I have a Prolog implementation of this, as well as a paper describing
it, available from my web page.  It's all implemented by adding extra
arguments (only as many as are necessary) to Prolog predicates, so
it's pretty efficient.  Give it a try.  Feedback welcome.


-Peter Schachte               | American business needs a lifting purpose
mailto:pets at cs.mu.OZ.AU       | greater than the struggle of materialism.
http://www.cs.mu.oz.au/~pets/ |     -- Herbert Hoover 
PGP key available on request  | 




More information about the users mailing list