DCG translation not steadfast
See original GitHub issueWas 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:
- Created a year ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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:With this definition, which seems to make intuitive sense, we have:
It works as expected, right? But on the other hand, the maximum of 1 and 0 is unexpectedly 0 if we ask like this:
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
: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:
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.
Steadfast in connection with DCG is defined in the DCG Draft.
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.