for review: EDCGs and insts

Peter Nicholas MALKIN pnmalk at students.cs.mu.OZ.AU
Mon Mar 2 16:20:31 AEDT 1998



On Mon, 2 Mar 1998, Peter Schachte wrote:

> On Sun, 1 Mar 1998, Peter Nicholas MALKIN wrote:
> 
> > The hmode declaration is of the following form:
> >
> > :- hmode(Hidden, [changed(Mode, Mode),] [passed(Mode),] 
> >                         [consumed(Mode),] [produced(Mode)]).
> >
> > Where Mode is a Mercury mode.
> 
> Shouldn't they be insts?  If not, why does changed need two modes?

No. I assume you mean that, say if a hidden argument of form `passed'
was given an instantiation of INST then the mode MODE would be inferred to
be;

:- mode MODE :: INST -> INST.

BUT, the hidden argument forms are not reflections of variable
instantiations but instead of the flow of the hidden argument. Do not
think of hidden arguments in terms of variable instantiation.

It is possible to have a hidden argument of form passed with the mode out.

The forms make the most sense when thought of in terms of predicate calls
within the body of a clause:

Passed indicates that the predicate call recieves a hidden argument and
passes on the same hidden argument, to the next goal.

Consumed indicates that the predicate call recieves a hidden argument but
does not pass it on.

Produced indicates that the predicate creates a hidden argument and passes
it on.

Changed indicates that the predicate recieves a hidden argument creates a
new version to be passed on, hence you need to modes, one to give the mode
of the hidden argument recived and one to give the mode of the hidden
argument passed on. Using a changed hidden argument is analogous to using
DCG notation. A changed form could be thought of as a hidden argument that
is consumed and then produced.

I probably was not very clear in my explanation of EDCGs, if this makes it
clearer then please let me know so that I can change the documentation.

I suggest you have a look at the example;

~pnmalk/MERCURYDEVELOPERS/calculator.m

Which replaces DCG notation with EDCG notation using a changed hidden
argument.

Peter




More information about the developers mailing list