We had an interesting discussion oi Hilog syntax and semantics this morning. I’d like to summarize what I understood.
Syntax issues: XSB extends Prolog term syntax to allow the functor position to be an arbitrary (hilog) term. Ciao extends Prolog term syntax to allow the functor position to be a variable.
In each case a term like X(A,B) is syntactic sugar for the Prolog term $$(X,A,B), where the $$ is some atom. In Ciao it is call/n; in XSB it is apply/n.
Semantic issues: The question is what is the semantics of the $$. In XSB it is an uninterpreted symbol (i.e., not the semantics of the Prolog predicate apply/2; i.e., apply was probably a poor choice for this symbol by the XSB implementers). In Ciao the semantics of $$ (call/n) is, appropriately, the Prolog semantics of call/n.
An important implication of this difference is shown by the example (thanks, Manuel):
?- P=append([1,2,3]), P([4,5,6],X).
In Ciao semantics, with the usual definition of append/3, this would be equivalent to::
?- append([1,2,3],[4,5,6],X).
In XSB semantics, the above call with P (with the irrelevant definition of append/3) would be failure. One would have to give a definition of the apply/3 predicate, maybe like:
append()(L,L).
append([X|L1])(L2,[X|L3]) :- append(L1)(L2,L3).
to get the same answer as Ciao gets to that query (with P).
I suspect that Ciao does not allow a term with a variable functor in the head of a rule. When one gives definitions of predicates, one must use the “unfactored” version I suspect. XSB does allow definitions to be given directly in hilog syntax. Allowing that is Ciao seems non straightforward. E.g., XSB allows a definition:
X(a,b),
and query ?- Y(Z,b). which will bind Y to X and Z to a. (How useful this is may be questioned:-).
Or similarly
p(a,b).
and a call of ?- X(a,b). with X being bound to p. I don’t see how to do either of these in Ciao. Of course these may seem unreasonable uses, and the reasonable uses of hilog terms in the heads of rules may be appropriated compiled for Ciao’s semantics with some restriction and translation.
Another thought: I assume Ciao allows embedded terms to have variable functor symbols. (Is this true?) Assuming so, then consider:
?- X = Y(a), X = p(a).
This would seem to fail since the first X would be call(Y,a) and the second would be p(a). This would succeed in XSB and is why XSB needs to know that p is a hilog symbol. But maybe Ciao doesn’t allow embedded terms with variable functor, or just defines this to fail?
Thoughts?
-David