Prolog Partial Predicates

Prolog is homoiconic, a fancy word meaning our code is also data so we can manipulate it as such. This means we can pass around predicates as if they were data, and then call them. This has been the case since the very first Prolog in which you could do this:

?-

Rather than just leaving that X floating around by itself, it's generally advised to make it explicit by wrapping it in a call predicate. Note, we've not given the arity for call because it varies from dialect to dialect, but you'll generally find it sufficient.

One of the main advantages of call is that you can add additional arguments to a partial predicate, like so.

?-
?-

We've passed foo(A) and B around until we got to call(foo(A), B). This has called foo(A, B) to find the answer. Magic! In Tau-Prolog (what's running in your browser) we can have up to 8 arguments passed to call.

If you're coming from a functional language, you might think "Oh, that's just currying". It's not quite, but we can use it to solve the same kind of problems, such as when writing higher-order predicates like map, reduce and filter.

All in all, call is rather useful, particularly when you don't know what predicate will be called, or when the required argument is not yet available, or when the same predicate will be called with many different arguments. However, depending on how your Prolog manages itself you may loose a performance benefit that comes from clever compile-time indexing as call works in runtime.