[mercury-users] Uniqueness modes etc

Dr Mark H Phillips mark at austrics.com.au
Tue Dec 30 18:15:52 AEDT 2003


On Tue, 2003-12-30 at 14:31, Fergus Henderson wrote:
> > Is logic programming based around a search for true predicates?  Is
> > there anything you would recommend I read on logic programming?
> 
> If you are looking for introductory material on logic programming,
> I would recommend the first six chapters of Sterling and Shapiro's
> book "The Art of Prolog".

Okay, thanks.

> > I am still curious about other possible solutions however.  One
> > thought which occured to me... would it be possible to do
> > something like:
> > 
> >   Q(N::in, Fn::out, Q::di, Q::uo)
> > 
> > Ie, a procedure Q which (along with the arguments N and Fn) takes
> > itself as a di parameter and returns a new procedure with the same
> > arguments as a uo parameter.
> 
> No, that is not allowed; it is a mode error (actually a uniqueness error),
> for the same sort of reasons as your original example.
> 
> > In essence Q would be a self-modifying
> > procedure, but strictly the di and uo modes would mean that Q 
> > would represent a series of evaluate-only-once procedures.
> 
> In Mercury, variables are immutable; once bound, each variable refers
> to a single value for the duration of its scope, not to a series of
> different values.

I think I'm misunderstanding something, which I probably should try and
clarify before going any further.  From your reply to my original
email:

  > Is it possible to have a variable, x say, and send it into a
  > function using the di mode, and extract it out again using 
  > the uo mode?
  
  Yes.

I thought you meant that I could do this:

  :- pred r(int, int, int, int).
  :- mode r(di, uo, in, out) is det.
  r(X, Y, N, Fn) :- ....
  ...
  r(X_0, X_0, N, Fn)

meaning that there are two versions of X_0, the first with 
scope up until the evaluation of r, and the second with 
scope starting immediately after the evaluation of r.

So when I write:

> > In essence Q would be a self-modifying
> > procedure, but strictly the di and uo modes would mean that Q 
> > would represent a series of evaluate-only-once procedures.

what I was meaning was that there would be a series of versions of
Q, each having scope starting from its production using uo, through
to its destruction when it is first called and with itself passed in
as a di parameter.

What am I misunderstanding?

Thanks,

Mark.


--------------------------------------------------------------------------
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