> From: Edmund Shing <E.Shing@computer-science.birmingham.ac.uk>
>
> Can anyone tell me why the following doesn't work in Poplog Prolog but does in
> other versions of Prolog? It is Edinburgh syntax and ought to work (according
> to the Poplog help file) but doesn't:
>
> [...]
> relations(R, charles, diana):-
> clause(X, true),
> X =.. [R, charles, diana].
>
> ?- relations(R, charles, diana).
>
> [...]
> ;;; PROLOG ERROR - INSUFFICIENT INSTANTIATION OF GOAL
I don't know about other Prologs, but the Poplog documentation clearly
states that this will *not* work. From PLOGHELP * CLAUSE
A goal of the form
?- clause(Head, Body)
will succeed if there is a clause in the database with given Head and
Body. This goal may be resatisfied if there are several clauses whose
heads and bodies match Head and Body. In the first solution, Head and
Body will be instantiated to the first such clause. Subsequent solutions
instantiate Head and Body to all the others in the same order as the
clauses appear.
[...]
When this predicate is called, Head should be instantiated enough that
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the main predicate of the clause is known.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I don't think there is an acceptable way of doing this in Poplog Prolog
(I'm no Prolog expert, so somebody correct me if I'm wrong...) You could
restate your problem with something like.
relation(married, charles, diana).
relation(seperated, charles, diana).
?- relation(R, charles, diana).
or, if you're feeling very, very, brave, delve into the source code for
Prolog. The following nasty hack does what you want, but I wouldn't want
to guarantee it working in future versions of Poplog (and is of course
terribly inefficient since it has to check every predicate) :-)
section $-prolog => relation_of_arity;
define relation_of_arity(f, n, c);
lvars f, n, c;
define lconstant do_check(pred);
lvars pred, arity;
pred_spec(pred) -> arity -> pred;
if n==arity then
prolog_unifyc(pred, f, c);
endif;
enddefine;
app_predicates(do_check);
enddefine;
endsection;
$-prolog$-relation_of_arity -> prolog_valof("roa", 2);
----
relations(R, charles, diana):-
roa(R, 2),
C =.. [R, charles, diana],
clause(C, true).
?- relations(R, charles, diana).
Hope this helps.
aids
|