Home > Archive > Prolog > October 2004 > List-operation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Paul Summer 2004-10-01, 3:57 pm |
| Hi,
how can I define a predicate alltrue(L) that checks whether all facts in the
list L are true (please with code)?
Greetz,
Paul
| |
| David Vago 2004-10-01, 3:57 pm |
| Well, it is fairly simple, just think about it for a short time.
Surely, when L is an empty list, alltrue(L) must succeed.
If L contains at least one element, than the first element
must be a true fact, and alltrue/1 must be true for the
tail of the list. After you had thought about it, you can
simply write the code just be following the logical reasoning.
alltrue([]).
alltrue([Head|Tail]) :- call(Head), alltrue(Tail).
Dave
"Paul Summer" <psummer1@yahoo.com> wrote in message
news:2s5e92F1f6n8rU1@uni-berlin.de...
> Hi,
>
> how can I define a predicate alltrue(L) that checks whether all facts in
> the list L are true (please with code)?
>
> Greetz,
>
> Paul
>
|
|
|
|
|