question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DCG translation not steadfast

See original GitHub issue

Was running this test case:

p --> \+ q.
q --> {write('did you call me?'), nl}.

In Tau Prolog 0.3.2 (beta) I get:

p([a],[]).
false.

On the other hand SWI-Prolog gives me:

?- p([a],[]).
did you call me?
false.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
triskacommented, May 5, 2022

@gilbert: “steadfast” is hard to define in general. A “classical” example of a definition that is not steadfast is usually given for max/3, which we can wrongly define as:

max(X, Y, X) :- X > Y, !.
max(_, Y, Y).

With this definition, which seems to make intuitive sense, we have:

?- max(1, 0, X).
   X = 1.

It works as expected, right? But on the other hand, the maximum of 1 and 0 is unexpectedly 0 if we ask like this:

?- max(1, 0, 0).
   true.

The predicate is not steadfast in the sense that, by instantiating arguments in the query, we can trick it to yield an answer that we actually did not intend to define. The (1980’s) textbook way to solve this issue in this concrete case is to delay the unification of X and the third argument to occur only after the !/0:

max(X, Y, Z) :- X > Y, !, X = Z.

It is clear that nobody wants to write such code and that moreover, nobody wants to risk running into such unexpected problems, and we would therefore of course simply define, via a single clause:

max(X, Y, Z) :- Z #= max(X, Y).

and thus get a shorter and significantly more general definition, at least as we reason about integers, as is normally also the case.

In the case under discussion, “steadfastness” is, somewhat analogously, a guarantee that certain parts of the grammar rule are executed no matter the instantiation of arguments: We cannot “trick” the definition to yield unexpected results by instantiating parts of the query.

2reactions
Jean-Luc-Picard-2021commented, May 5, 2022

Steadfast in connection with DCG is defined in the DCG Draft.

Unbenannt

This document is available for everybody: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/dcgs/dcgsdraft-2019-06-03.pdf

If we interpret execution as including side effects… but I didn’t check what 7.7.1 says.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DCG Expansion: Is Steadfastness ignored? - prolog
Your translation is a valid one. It does not influence steadfastness. However, it still might not be very desirable.
Read more >
Translation of Definite Clause Grammar rules - UCR CS
The left hand side of a DCG rule must consist of a single non-terminal, ... Each grammar rule is translated into a Prolog...
Read more >
Translation of Definite Clause Grammar rules
Translation of Definite Clause Grammar rules. The procedural interpretation of a DCG rule is that it takes an input list of symbols or...
Read more >
sens.cse.msu.edu/Software/XSB/docs/userman/dcg.tex
In either case, the arguments required for the input and output lists are not written explicitly in the DCG rule, but are added...
Read more >
Prolog Language - SICStus Prolog Release Notes
The exact rules for translating DCG rules to plain Prolog clauses have not been ... In some cases, a non-steadfast translation was produced...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found