3

Some "predicate indicators" (this is the ISO Standard terminology for a syntactic name/arity expression denoting a predicate or functor (both of these terms are equivalent) are not content with a single slash, but actually take two. This always occurs in the context of DCGs. Examples:

  • syntax_error//1: "Throw the syntax error Error at the current location of the input. This predicate is designed to be called from the handler of phrase_from_file/3."
  • js_expression(+Expression)//: "Emit a single JSON argument."
David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
  • 1
    See [this draft](http://www.complang.tuwien.ac.at/ulrich/iso-prolog/#dcg). – false Mar 16 '20 at 23:16
  • Added text to the question [Is this Prolog terminology correct? (fact, rule, procedure, predicate, …)](https://stackoverflow.com/questions/49898738/is-this-prolog-terminology-correct-fact-rule-procedure-predicate) for completeness. – David Tonhofer Mar 17 '20 at 08:57

2 Answers2

4

According to the recent drafts WDTR 13211-3 (3.19) this is called a non-terminal indicator. Similar to a predicate indicator (3.131) it is used to denote one particular non-terminal.

Note that most implementations translate a non-terminal nt//n to a predicate nt/n+2. You cannot rely on the precise way of translation, though. And thus the outcome of calling a non-terminal directly by calling the corresponding predicate, that is, with the same name and two extra arguments is not defined. In particular the second additional argument has to be handled with care. A direct use might violate steadfastness, in particular when using .

false
  • 10,264
  • 13
  • 101
  • 209
  • Related blog post: "DCGs provide a threading state abstraction: don't break it" @ https://logtalk.org/2019/06/24/dcgs-preserving-abstraction.html – Paulo Moura Mar 17 '20 at 10:55
  • 1
    @PauloMoura Added as reference in DCG [tag](https://stackoverflow.com/tags/dcg/info) :) It was nice to finally be able to update a tag without needing approval. – Guy Coder Mar 17 '20 at 12:32
3

What is the meaning of a double slash // after the predicate name in Prolog, appearing in the context of DCGs?

It is used by the term rewrite system of Prolog (SWI-Prolog src), but for a person it lets you know that the predicate is a DCG and has two hidden arguments added to the end of the predicate.

For example here is a very simple DCG that has 1 visible argument.

simple_dcg(X) -->
    { X is 1 + 2 }.

When the listing is seen

?- listing(simple_dcg).
simple_dcg(X, A, B) :-
    X is 1+2,
    B=A.

true.

the two extra hidden arguments (A, B) appear.


If you have been following my EDCG questions on SWI-Prolog forum then you know it can get much more complicated.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
  • 1
    @DavidTonhofer I stared DCGs but should have started with difference list then went to DCGs, but am now moving onto EDCGs, and I only see those as a way point to something more. Not sure of which way to go beyond EDCGs as it gets in to more papers than practical code so would have to learn [program transformations](https://www.swi-prolog.org/pldoc/man?section=progtransform). More than happy to discuss in the SWI-Prolog forum. – Guy Coder Mar 17 '20 at 10:45
  • Not for the moment but thanks. I need to clear a lot off my plate first. – David Tonhofer Mar 17 '20 at 10:46