Re: trying to flatten a list
- From: rafe@xxxxxxxxxxx
- Date: 27 May 2005 18:52:05 -0700
Anders Lindén wrote:
>
> whats the difference between
> not(A) :- A,!,fail;true.
> and
> not(A) :- !,A,fail;true.
With
not(A) :- A, !, fail ; true.
a goal not(P) will call P. If P succeeds, the cut
commits to this arm of the disjunction, and then
the clause fails.
If P fails, Prolog backtracks into the second arm
of the disjunction which succeeds.
With
not(A) :- !, A, fail ; true.
a goal not(P) starts by committing to the first
disjunct. Then either P succeeds and we go on
to fail, or P fails and so not(P) fails. That
is, this definition of not/1 will always fail!
-- Ralph
PS What is it with Prolog programmers and bad code
layout? Adding a bit of whitespace doesn't cost
that much extra effort...
.
- References:
- trying to flatten a list
- From: Anders Lindén
- Re: trying to flatten a list
- From: Anders Lindén
- trying to flatten a list
- Prev by Date: Re: Prolog [book] for beginners.
- Next by Date: Re: trying to flatten a list
- Previous by thread: Re: trying to flatten a list
- Next by thread: Re: trying to flatten a list
- Index(es):
Relevant Pages
|
|