Re: negotiation by failure- list operations
- From: "Brian Hulley" <brianh@xxxxxxxxxxxx>
- Date: 14 Jun 2005 13:28:12 -0700
matthiasse@xxxxxxx wrote:
> well Brian as i stated before- he wants the "YES" given back in prolog-
> not the "no"- and he wants to see it - maybe its just a liddle glitch
> in your code that îf E isnt in the list it sure succeeds- but it
> doesnt give out the "yes" -
>
> maybe u should try it urself - it keeps given back the no-
Right I finally understand what ne0 wanted.
However "yes" and "no" is just due to the vagaries of the top level and
shouldn't really be bothered about all that much. For example, in SWI
Prolog, if you compare these queries:
1 ?- true.
Yes
2 ?- X = a.
X = a
% At this point the SWI top level doesn't say "Yes" because it
% thinks there might be another solution
% If I type ';' it will try to find the other solution
;
No % This "No" refers to the fact that there was no other solution
3 ?-
Therefore in this prolog it doesn't matter what you do to delete1 - any
query with variables in it is never going to reply "Yes". In my own
implementation of Prolog (not yet released), if I add a cut to the
first clause of delete1, so that there are no choicepoints left, I get
a "Yes" as expected. This is because my top-level only waits for the
user to type ';' if there are any choice points left to try.
Ie you'll get a "Yes" with some implementations and a "No" with others,
depending on how the implementation optimizes the choicepoints out of
the code and the implementation of the top-level loop. Adding extra
cuts may help some implementations but won't change the behaviour of
others in this respect eg:
delete1(_,[],[]) :- !. % extra cut here to eliminate choicepoint
delete1(E,[E|T],T) :- !.
delete1(E,[H|T],[H|DT]) :-
delete1(E,T,DT).
SWI-Prolog:
1 ?- delete1(a,[b,c],X).
X = [b, c] ;
No
2 ?-
My own Prolog (not yet released - www.metamilk.com):
?- delete1(a,[b,c],X).
X = [b, c]
yes
?-
Cheers, Brian.
.
- Follow-Ups:
- Re: negotiation by failure- list operations
- From: Bart Demoen
- Re: negotiation by failure- list operations
- From: Bart Demoen
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- References:
- negotiation by failure- list operations
- From: ne0
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: ne0
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: matthiasse
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: ne0
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: matthiasse
- negotiation by failure- list operations
- Prev by Date: Re: negotiation by failure- list operations
- Next by Date: Re: negotiation by failure- list operations
- Previous by thread: Re: negotiation by failure- list operations
- Next by thread: Re: negotiation by failure- list operations
- Index(es):