0
$\begingroup$

I've been playing around with prolog and realised something. You can do everything without predicate names.

e.g. Just change all predicates

$$a(b,c,d,e,..)$$

into

$$prop(a,b,c,d,e,..)$$

Where $prop$ is some character that you can use for all function names.

So $isRed(X)$ becomes $prop(isRed,X)$.

Which makes me wonder if there is any point to prolog having function heads? Couldn't everthing be done using lists? e.g. $loves(romeo,juliet)$ could just as easily be written $[loves,romeo,juliet]$ without loss of information.

Have I missed something or is there anything special about predicate function heads?

$\endgroup$

1 Answer 1

1
$\begingroup$

One issue is efficiency. Having different predicates means more efficient compilation. It also allows for separate compilation, using modules, which is important for even medium-sized programs. Additionally, using the WAM terminology, you will end up with a lot more choicepoints than you expect.

Modern compilers go to a lot of trouble to perform optimisations using type and mode inference (and annotations, if they are available). You lose all that when you give the compiler less information.

Another consideration is semantic, especially considering non-logical control such as the cut. Consider this:

p(X) :- q(X), !.
p(X) :- r(X), \+ s(X).

a(X) :- b(X).
a(X) :- c(X).

Here, the cut operator prunes choicepoints in the call to p/1. If you translated this into "headless" form:

pred(p,X) :- pred(q,X), !.
pred(p,X) :- pred(r,X), \+ pred(s,X).

pred(a,X) :- pred(b,X).
pred(a,X) :- pred(c,X).

Now, the cut operator prunes choicepoints in the call to pred/2. If you promise that you only ever call pred/2 with the first argument bound to an atom, that's probably okay, but if you are doing higher-order programming, it may not behave as you expect.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.