tomk@uk.co.integ (Tom Khabaza) writes:
>Just out of interest, which Prologs allow clause/2 with an
>uninstantiated first argument? This is rather naughty since most
>textbooks will say it's illegal.
There are many reasons why it's illegal. One of them is that there
are a lot of built-in predicates. They are well defined, but as a
rule they are not defined by clauses. For example,
clause(X is Y, Body)
cannot succeed, because there is likely to be no such clause, but
it can't fail either, because is/2 is defined. The only other
possibility is an error message. Now, if you ask about predicates
of arity 2, is/2 is one of them. So if
clause(Head, true),
Head =.. [Relation, charles, diana]
were to try _any_ solutions, it would eventually try Head = _ is _.
Not very sensible.
DEC-10 Prolog had a built-in predicate
current_predicate(Symbol, Head)
which was _almost_ what you want. Other Prologs have added
predicate_property(Head, Property)
which *will* solve for their first argument, letting you do
predicate_property(Head, interpreted),
Head =.. [Relation, charles, diana],
clause(Head, true)
In Poplog, predicate_info/2 serves much the same purpose.
user_predicate(Name, Arity) :-
current_predicate(Name, Head),
functor(Head, Name, Arity),
predicate_info(Name/Arity, [user_predicate|_]),
This should solve for Name and Arity, so you can write
user_predicate(Relation, 2),
Head =.. [Relation, charles, diana],
clause(Head, true)
This is still a rather silly thing to do because it is going to try
all sorts of things that are totally unrelated to those unfortunate people.
--
Richard A. O'Keefe; ok@goanna.cs.rmit.oz.au; RMIT, Melbourne, Australia.
The last good thing written in C was Franz Schubert's Symphony number 9.
|