Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the colon (:) exactly stand for in Swi-Prolog?

Tags:

prolog

colon

I could not find explicitly what (:) stands for in prolog.
In interactive mode you can see the following evidence:

?- display(a:b).
:(a,b)
true.

?- display([a,b,c]).
.(a,.(b,.(c,[])))
true.

?- display(a:b:c:[]).
:(a,:(b,:(c,[])))
true.

?- a:b:REST = a:TAIL.
TAIL = b:REST.

For what purpose (:) is introduced? I could not find any details for it in www. Seems that it gives another syntactic way of talking about recursive structures as Lists.

We can say that it is Right-associative, what is its priority number?

:-op(??, xfy, :).

Is there a way to list all such kind of implicit functors?

listing(op). %of course this does not work
like image 513
Fibo Kowalsky Avatar asked Oct 06 '12 12:10

Fibo Kowalsky


1 Answers

That's the module qualifier, you can see its declaration with this:

?- current_op(X,Y,:).
X = 600,
Y = xfy.

Modules are an important extension to Prolog, particularly required for large programs, but miss from ISO standard. SWI-Prolog has (as usually) a pragmatic viewpoint on this, and implements an useful approach.

OT inspecting operators, you could find this snippet useful:

oplist :-
    setof((A,C,B), current_op(A,B,C), L),
    maplist(writeln, L).
like image 152
CapelliC Avatar answered Sep 26 '22 08:09

CapelliC