1
votes

I find that some 'functions' in Prolog return some value, like min/2 and max/2, etc, even though vast majority return only true or false. Are these called or grouped differently than boolean ones? Also how can one identify if they are returning a value other than going through documentation of each function. Can I find a list somewhere of functions which return some value?

1
Predicates don't return something, they unify variables with values. Furthermore a predicate succeeds (true) or fails (false).Willem Van Onsem
What about max and min?rnso

1 Answers

2
votes

Operations such as min, max, log, etc, are specific arithmetic functions and not the same as a standard predicate. They are evaluated using is/2, =:=/2, etc. Standard predicates do not return a value, not even true or false. They succeed or fail. That's not the same thing as returning a value. To return a value as a function would imply you could capture that value in a variable, but there's no true/false datum returned from the predicate. The Prolog interpreter just shows true or false to let you know if it succeeded or not. Some interpreters might output yes or no rather than true or false, respectively.

In order to know if a given term is a predicate or function, the documentation referenced above is your best bet as it lists all the valid arithmetic functions. It's all in one place so not that difficult. Functions only operate on numbers. You could also use, for example, current_arithmetic_function(Head), as described in the documentation, to determine if Head is an evaluable function.