Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Problem passing a value through

Unread post by Martin Meyer »

Hi Thomas,

please check this construct:

Code: Select all

class predicates     passThrough : (unsigned, unsigned [out]) -> unsigned. clauses     passThrough(X, X) = X.   clauses     run() :-         L1 = [passThrough(0, X1), passThrough(X1, X2)],         stdIo::write("L1 = ", L1, ", X2 = ", X2, '\n'),         L2 = [[passThrough(0, Y1), passThrough(Y1, Y2)]],         stdIo::write("L2 = ", L2, ", Y2 = ", Y2, '\n').
Outputs of it vary. One of my tries for example has output:

Code: Select all

L1 = [0,0], X2 = 0 L2 = [[0,36773712]], Y2 = 36773712
Regards
Martin
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer »

This similar code throws error c603 : The flow pattern '(i,o)' does not exist for 'main::useValue/2':

Code: Select all

class predicates     passThrough : (unsigned, unsigned [out]) -> unsigned. clauses     passThrough(X, X) = X.   class predicates     useValue : (unsigned*, unsigned). clauses     useValue(List, X) :-         stdIo::write(List, ", ", X, '\n').   clauses     run() :-         useValue([passThrough(0, X1), passThrough(X1, X2)], X2).
Is the error intended, resp. can you make such constructions work out in future?

Best regards
Martin
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Martin, why do you need the passThrough/3 predicate?

Harrison
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer »

Hello Harrison,

that passThrough predicate from the example is quite useless. It is just a rigorously stripped down version of my 'real' code. For the example I deleted everything, which is not needed to demonstrate the issue.

Obviously there is a work around to the problem. Just expand the construction to

Code: Select all

        Y1 = passThrough(0, _Y1),         Y2 = passThrough(Y1, _Y2),         L2 = [[Y1, Y2]],         stdIo::write("L2 = ", L2, ", Y2 = ", Y2, '\n').
OK, so your question is: What use do I have for "pathThrough" predicates? In my 'real' code the class declaration contains amongst others these predicates:

Code: Select all

predicates     var : (         universe{Atomic} Universe0,         universe{Atomic} Universe1 [out])         -> refTerm{Atomic} NewVariable.   predicates     unify :(         refTerm{Atomic} Rt_a,         refTerm{Atomic} Rt_b,         universe{Atomic} Universe0,         universe{Atomic} Universe1)         procedure (o, i, i, o)         procedure (i, o, i, o)         procedure (o, o, i, o)         determ (i, i, i, o).   predicates     append : (         refTerm{Atomic} ListRtA,         refTerm{Atomic} ListRtB,         refTerm{Atomic} ListRtAB,         universe{Atomic} Universe0,         universe{Atomic} Universe1 [out])         nondeterm.
The purpose of the class is to implement reference variables (cf. tutorial). I've been struggling with that topic for some time (Determ besides Side Effects, Callback Actions for Exceptions and Failure). The challenge is, to set up a unify predicate, which is determ and does not impose restrictions to the use of cuts.

In my solution the reference variables are not objects but are of an algebraic domain (i.e. refTerm{Atomic}). The bindings of the reference variables are not stored inside the variables, but are held altogether in a variable of the algebraic type universe{Atomic}. So, most predicates of the class have two universe parameters. The first is to input the already done bindings, and the second to output the (possibly) updated bindings.

Consider a call to a list append predicate, which looks in some standard prolog for example like append(ListA, _, ListAB). The call has no solution (i.e. fails immediately), iff ListA cannot be unified with any front part of ListAB. With my class (when the current universe is say for example U7) an equivalent call could be

Code: Select all

    append(ListA, var(U7, U8), ListAB, U8, U9)
But, as told, that doesn't work fine. Instead I must code

Code: Select all

    ListB = var(U7, U8),     append(ListA, ListB, ListAB, U8, U9)
That's the "passThrough" predicate in my 'real' code.

Best regards
Martin
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Thanks, Martin!

That is a mind-expanding explanation that helps me understand some concepts I haven't used before.

Harrison
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Hi Martin, we will look at these problems (but I am not sure it will be our highest priority).
Regards Thomas Linder Puls
PDC
Post Reply