Reputation:
Good morning, I am stuck on a rule of a Prolog program found in OsmAnd. This is a simplified version:
dest(D) -- ['dest.ogg'|Ds] :- name(D, Ds).
I can't figure out what is the meaning of --
as it is the first time I see such a construct in Prolog programs. It looks like a substitution read as follows: "dest(D)
is the list obtained by replacing Ds
in ['dest.ogg'|Ds]
if name(D, Ds)
".
Also, I tried to look for "--" in several Prolog manuals (e.g. SWI-Prolog) but I couldn't find anything related to such construct.
Any suggestion? Is it a custom construct?
Upvotes: 4
Views: 118
Reputation: 476659
As far as I know, the --
part is not specific to SWI. It is an operator. Probably in the file you will somewhere see:
:- op(900, xfx,--).
(or something similar)
So here the operator (--)/2
is defined. Next you can use (--)/3
as a predicate (or functor) with infix notation. So in fact:
dest(D) -- ['dest.ogg'|Ds] :- name(D, Ds).
Is short for:
--(dest(D),['dest.ogg'|Ds]) :- name(D, Ds).
Which is a simple (well simple, it has a weird name) predicate definition. But by defining the operator with precedence 900 (at least in this answer), and mode xfx
you can use it between two terms as an operator.
In Prolog, is
, +
, -
, *
, etc. are also operators. If you write X is 2+2
, you have actually written is(X,+(2,2))
. So here the +
is replaced by a functor, and is
is a predicate. There is thus nothing special about is/2
either: it is simply a predicate that interprets a functor that describes the syntax tree of an expression that should be evaluated.
This entry on Operators of the SWI Prolog manual explains operators in more depth.
Upvotes: 6