Re: negotiation by failure- list operations
- From: Matthew Huntbach <mmh@xxxxxxxxxxxxxx>
- Date: Fri, 17 Jun 2005 09:53:18 +0100
On Thu, 16 Jun 2005, ne0 wrote:
great that so many people are getting into my propblem. i think i found a solution - maybe u guys can check it
delete1(E,L1,L2):-not(member(E,L1)),write(yes),L2=L1,!. delete1(_, [], []). delete1(Head, [Head | Tail], Result):-!, delete5(Head, Tail, Result). delete1(Element, [Head | Tail], [Head | NewTail]):-!, delete5(Element, Tail, NewTail).
what happens on swi ? ==== ?- delete1(a,[b,d],X). yes
X = [b, d] ;
No ===
i think thats what i searched for or is there maybe a shorter way- especially for not getting to answer the X question ? can i make a cut with a real stop! - and of course my "yes" String ?
It would help if you specified better what exactly you want.
This is what you wrote before:
"all i need is a modified delete1 predicate that throws back a YES if x isnt in the List. - the point is the yes - not deleting all matching elements in the list.
its like a if then construction
delete1(x,[L1],Y). if x isnt in the list - then halt and give back a YES, if x is in the list- procede with delete"
Nowhere in this did you say you wanted the word "yes" to be printed on the screen. A predicate call that causes the word "yes" to be printed is not the same thing at all as a predicate call that succeeds. I find this with novice programmers in other languages - sometimes they can't see the difference between a method call which returns a value and a method call which causes a value to be printed on the output stream.
In your original wording, I think it would have been assumed that
when you wrote "give back a YES" and "throw back a YES" you meant
"succeed". Predicate calls in Prolog don't return values, they either
succeed or fail, but they may have the side-effect of binding an
unbound variable argument, which is how they return results. So it looked like you wanted a predicate whose third argument
is the result of deleting the first from the second assuming the
second is a list, and which always succeeded, with the third
argument equal to the second if the first does not occur in the second.
Matthew Huntbach .
- References:
- negotiation by failure- list operations
- From: ne0
- Re: negotiation by failure- list operations
- From: Nameless
- Re: negotiation by failure- list operations
- From: Brian Hulley
- Re: negotiation by failure- list operations
- From: Nameless
- Re: negotiation by failure- list operations
- From: matthiasse
- Re: negotiation by failure- list operations
- From: ne0
- negotiation by failure- list operations
- Prev by Date: Re: cross-module asserting/retracting - is this a good thing?
- Next by Date: Re: cross-module asserting/retracting - is this a good thing?
- Previous by thread: Re: negotiation by failure- list operations
- Next by thread: Re: negotiation by failure- list operations
- Index(es):
Relevant Pages
|
|