[mercury-users] Partially instantiated modes

Thomas Conway conway at cs.mu.OZ.AU
Fri Nov 12 16:32:40 AEDT 1999


On Fri, Nov 12, 1999 at 12:36:16PM EST, Robert Ernst Johann JESCHOFNIK wrote:
> On Fri, 12 Nov 1999, Thomas Conway wrote:
> 
> > Actually I lied slightly - the code was already a DCG wrt the io__state.
> > This is (as Peter Schachte has pointed out more than once) the problem
> > with DCGs. Maybe there is something to his Syntactically Quiet Threading
> > (TM) (aka global variables) after all....
> 
> Here is a message that I saved, knowing that it would be usefull one day
> :)
> 
> >From Herr Conway himself, 13th May 1999:
> FWIW, since one ends up wanting a mini-dcg inside another predicate,
> here is a programming trick I use:
> 
>         ... some non-dcg code ...
>         call((pred(in, out) is det -->
>                 set_a(1),
>                 set_b('c'),
>                 set_c("dee"),
>                 set_d(X)
>         ), OldState, NewState),
>         ...
> 

So, what do we have then?

Mk 1:
	... io__state DCG ...
	{ call((pred(in, out) is det -->
		new_var("X1", X1),
		new_var("X2", X2),
		...
	), VS0, VS1) },

Okay, so this is illegal currently because it's illegal to curry output
arguments: you'll get mode errors relating to X1, X2, etc, so lets try
again:
Mk 2:
	{ call((pred( X1::out, X2::out, X3::out, ...
			in, out) is det -->
		new_var("X1", X1),
		new_var("X2", X2),
		...
	), X1, X2, X3, VS0, VS1) },

Well, aside from the variable naming issues, I have to mention each of the
Xn variables twice which is a double maintainance problem - though you're
right it's probably better than the large number of variables that would
need renumbering in the original code.

We can do better to some extent if we can shift some of the code that uses
the Xn variables into the call:
Mk 3:
	{ call((pred(Head::out, Body::out, in, out) is det -->
		new_var("X1", X1), ...

		{ Head = .... },
		{ Body = .... }
	), Head, Body, VS0, VS1) },

Which I guess is an improvement over all, but it still lacks the
finesse of the version using parially instantiated data structures.

-- 
 Thomas Conway )O+     Every sword has two edges.
     Mercurian            <conway at cs.mu.oz.au>
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list