Re: Prolog goals order



On 2006-08-24, Peter Wing Larsen <peterwing@xxxxxxx> wrote:
"Mauro DiNuzzo" <picorna@xxxxxxxxx> wrote in message
news:ZYHEg.145$%37.109@xxxxxxxxxxxxxxxxxxxxxx
I wish to submit an issue to the newsgroup. Perhaps it is old and not all
would be intereseted in.
However, it deals with the order of the goals in a clause. I will consider
mathematics for simplicity, but I think it could be applied whereever.
Prolog system reads goals in sequence (of course), also when it attempts
to
solve a set of goals. The only way to achieve the maximum knowledge over
the
given set of goals is to delay some of them. This is what happens by means
of attributed variables.
As an example, the goal:
?- X+1>10, read(X).
raises an instantiation error. (we have the mind full of examples like
this!)

My question is: "why Prolog does not change itself to overcome this
problem?".

This is also something I have thought about as a novice prolog learner. Is
there any reason why prolog is this way?

I think the answer is that Prolog is not a theorem prover, but a
programming language. If I write write(a), write(b) I want "ab" and
not "ba", so order matters. If the system starts reordering things,
you as a programmer quickly do not feel in control any longer. If
you have two goals and you cannot put them in the right order because
it is depending on the runtime behaviour there are several options.
Use conditional code as in (Cond -> a,b ; b,a) or use coroutining:

?- freeze(X, X+1>10), read(X).
|: 10.

X = 10

Yes
2 ?-

Coroutining is not part of standard Prolog, but an increasing number
provide it. See also when/2 and dif/2. Note however this is a lot
more machinery, making it slower as well as more difficult to
understand.

--- Jan
.



Relevant Pages

  • Re: Parallel Prolog
    ... further goals just perform tests on the binding. ... That's AND-parallelism: performing several ... possible in Prolog as well). ... another sort fo logic programming language rather than "parallel Prolog". ...
    (comp.lang.prolog)
  • Re: Beginners questions
    ... This tells Prolog that the goal "male" can be proved trivially. ... all we can ever tell Prolog is how goals can be proved. ... Redefining the built-in predicate \+ /1 ie bypassing its special ... eliza]))" because since you'd have overridden the special meaning given ...
    (comp.lang.prolog)
  • Re: lists
    ... This process is not unlike the process of developing a Prolog ... description says and you test that understanding by seeing if it can be ... is never re-prioritized with respect to existing goals as the agent ...
    (comp.lang.prolog)
  • prolog and backtracking
    ... I'M Trying To Write This Prolog Interpreter For A Subset Of The Prolog ... Grammar In Java And I Encountered Problems With Bakctracking. ... mother(carmen, jake). ... goals, i'm going to solve for all the possible goals ...
    (comp.compilers)
  • Re: Parallel Prolog
    ... goal to its right then makes choices dependent on that binding. ... It's also often the case that one goal binds a variable and several ... further goals just perform tests on the binding. ... possible in Prolog as well). ...
    (comp.lang.prolog)