----- Original Message -----
From: "Andrew_Days (sent by Nabble.com)" <lists@xxxxxxxxxx>
To: <prolog@xxxxxxxxxxxxxx>
Sent: Friday, December 16, 2005 6:18 AM
Subject: [SWIPL] VERY URGENT, CUT AND FINDALL/3
Andrew,
>
> Hi,
>
> 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.
>
Perhaps someone else can help with this as I'm not at all sure what it is
that you require.
>
> And I want to know a program write a list who not belongs
> simultaniosly a two lists, and i want to use findall/3.
> For example:
> A=[1,2,3,4,5,6].
> B=[3,4,8,7,6,1].
> L=[2,5,8,7].
>
Sounds like homework to me :) ! Still, all you have to do is write a
predicate, perhaps calling it, 'mem_not_both', that gives the following
results:
?- A = [1,2,3,4,5,6], B = [3,4,8,7,6,1],
findall(M, mem_not_both(M, A, B), Result).
A = [1, 2, 3, 4, 5, 6]
B = [3, 4, 8, 7, 6, 1]
M = _G21816
Result = [2, 5, 8, 7]
As a start, here is a possible implementation of its counterpart,
'mem_both':
mem_both(E, A, B) :- member(E, A), member(E, B).
which gives the following results:
?- A = [1,2,3,4,5,6], B = [3,4,8,7,6,1],
findall(M, mem_both(M, A, B), Result).
A = [1, 2, 3, 4, 5, 6]
B = [3, 4, 8, 7, 6, 1]
M = _G21792
Result = [1, 3, 4, 6]
Just provide a suitable body for, 'mem_not_both', and you're done :) !
Cheers,
Anthony Borla
|