----- Original Message -----
From: "Andrew_Days (sent by Nabble.com)" <lists@xxxxxxxxxx>
To: <prolog@xxxxxxxxxxxxxx>
Sent: Saturday, December 17, 2005 9:08 AM
Subject: [SWIPL] CUT(!) and FINDALL/3 URGENT
Andrew,
<original text>
I have an urgent doubt. For example when I ask to prolog
?- member( 3, [1,2,3]).
Yes
Is there any system variable associated with the prolog
answer "Yes" or "No" ???
I have this doubt because I want to use the answer in
programs (e.g. if answer=Yes then ....)
I know that is possible with :
The goal member(3,[1,2,3]) succeeds and you can use that in a
conjunction or in an if-then-else, as in
member(3,[1,2,3]), writeln('3 is a member of [1,2,3])
or
(member(3,[1,2,3]) ->
writeln(success)
;
writeln(failure)
)
but I need to Know how I can do with CUT.
</original text>
As I earlier mentioned, I do not understand what it is you require,
particularly with the use of cut/0, so cannot help you.
***********************************
<original text>
I have to know do a problem, where objective is to implement a function
where is order two lists for user. The program it will have write in screen
list of the elements that belong the two simultaneously. I need do this with
function findall/3.
Example:
<SNIP>
6- To calculate the elements that simultaneously do not
belong the 2 given lists
Escolher o numero que corresponde à opcção desejada:
|: 6.
Introduza a 1ª lista. Deve ser escrita na forma [elem1...elemn]- [1,2,3,4].
Introduza a 2ª lista. Deve ser escrita na forma [elem1...elemn]- [1,3,4,9].
The result it will have: [2,9]
</original text>
I already provided a near-complete model solution to this problem; a
slightly more complete one:
A = [1,2,3,4], B = [1,3,4,9],
findall(M, mem_not_both(M, A, B), Result),
write(Result), nl.
You will, however, need to make whatever changes are needed to fit this
logic into your application, as well as complete the body of the following
predicate:
mem_not_both(E, A, B) :- ...
In order to help you get started I provided an implementation of a predicate
that works in the same way, but gives the opposite result [i.e. it succeeds
if the element exists in both sets]:
mem_both(E, A, B) :- member(E, A), member(E, B).
An implementation of 'mem_not_both' is not much more complicated than this
since all you want is for the predicate to succeed when the element exists
in either one, but not both, of the sets. Think carefully about how this
might be accomplished using an approach similar to that used in 'mem_both'.
Short of completing your homework for you [and I'm *not* about to do that :)
!], I don't see how else I can help.
Cheers,
Anthony Borla
|