Suppose I have a predicate that sometimes gives me multiple outputs. Like this -
foo(Number, Out) :- Number < 10, Out = less_than_ten.
foo(Number, Out) :- Number > 0, Out = more_than_zero.
How might I get hold of all the values for Out
that foo
gives in another predicate, bearing in mind it can sometimes give one and sometimes give multiple (e.g. in a list)?
Edit - not quite sure the answers I've got answer my question so I'll be more specific. Taking the above predicate, I could run the query foo(5, Out).
This satisfies both rules, so if I run it in SWI-prolog I'll get this -
?- foo(5, Out).
Out = less_than_ten
Then I can enter a semi-colon to get prolog to backtrack and look for the other solution -
?- foo(5, Out).
Out = less_than_ten ;
Out = more_than_zero.
So if I was executing this predicate within another, how do I get all the valid values for Out, given Number = 5?