Re: Prolog goals order
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 24 Aug 2006 15:29:00 GMT
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
.
- Follow-Ups:
- Re: Prolog goals order
- From: Peter Wing Larsen
- Re: Prolog goals order
- References:
- Prolog goals order
- From: Mauro DiNuzzo
- Re: Prolog goals order
- From: Peter Wing Larsen
- Prolog goals order
- Prev by Date: Re: Prolog goals order
- Next by Date: Re: Prolog goals order
- Previous by thread: Re: Prolog goals order
- Next by thread: Re: Prolog goals order
- Index(es):
Relevant Pages
|