I wanted to ask about a behaviour of the forall element. When referred facts exist then it works correctly but when they do not exist at all then it evaluates to TRUE. Current behaviour is more like "Does not exist any item NOT MATCHING item" rather then "ALL items match" (the question is wheher the term ALL include also NONE)
The forall conditional element is simply a translation to other conditional elements. It doesn’t have specialized behavior that you would be unable to implement if it didn’t exist. So when you see patterns of this form:
(forall <x> <y>)
It's translated to this form:
(not (and <x>
(not <y>)))
If there are no matches for pattern <x>, then regardless of matches for pattern <y> the outermost not conditional element is matched.
I think of the forall wording as "for all occurrences of pattern <x>, pattern <y> is matched." The term all doesn't include existence. For all is basically the same thing as for every. For example:
if
claimant's-SSN-provided and
forall dependents-claimed
dependent's-SSN-provided
then
all-SSNs-provided
If I haven’t claimed any dependents, then the forall is satisfied which is the desired logic. If I haven’t claimed anyone, then I don’t need to supply SSNs for them, so the forall needs to be satisified if there are no dependents-claimed matches.
If you want logic that requires at least one occurrence of the first pattern in the forall CE, then you need to add this externally to the forall CE:
(exists <x>)
(forall <x> <y>)
As a historical note, the semantics and naming of the forall conditional element came from ART, the tool on which the syntax of CLIPS was based.
I wanted to ask about a behaviour of the forall element. When referred facts exist then it works correctly but when they do not exist at all then it evaluates to TRUE. Current behaviour is more like "Does not exist any item NOT MATCHING item" rather then "ALL items match" (the question is wheher the term ALL include also NONE)
Hello,
I wanted to ask about a behaviour of the forall element. When referred facts exist then it works correctly but when they do not exist at all then it evaluates to TRUE. Current behaviour is more like "Does not exist any item NOT MATCHING item" rather then "ALL items match" (the question is wheher the term ALL include also NONE)
Thanks for a clarification.
Vranoch
The forall conditional element is simply a translation to other conditional elements. It doesn’t have specialized behavior that you would be unable to implement if it didn’t exist. So when you see patterns of this form:
It's translated to this form:
If there are no matches for pattern <x>, then regardless of matches for pattern <y> the outermost not conditional element is matched.
I think of the forall wording as "for all occurrences of pattern <x>, pattern <y> is matched." The term all doesn't include existence. For all is basically the same thing as for every. For example:
If I haven’t claimed any dependents, then the forall is satisfied which is the desired logic. If I haven’t claimed anyone, then I don’t need to supply SSNs for them, so the forall needs to be satisified if there are no dependents-claimed matches.
If you want logic that requires at least one occurrence of the first pattern in the forall CE, then you need to add this externally to the forall CE:
As a historical note, the semantics and naming of the forall conditional element came from ART, the tool on which the syntax of CLIPS was based.
Cheers,
Gary
Last edit: Gary Riley 2015-01-16