Public bug reported:

gprolog seems to be producing incorrect results when using the phrase/3
builtin. In particular, the symptom is that when phrase/3 is used to
match a DCG that requires its input to start with a particular
string/list, and the input actually starts with something else, phrase/3
reports that there was a match (returning an unbound list for the
remaining unconsumed input), rather than reporting that there was no
match.

Example to reproduce: start gprolog, and give it the input line

phrase([2], [1,2], T).

Expected behaviour: gprolog answers "no": this query is equivalent to
"remove the prefix [2] from the list [1,2] and bind the remainder to T",
and [1,2] does not start with [2], so this task should be impossible.
I've verified that this is the expected/correct output against both
gprolog's documentation, and against swipl (a different Prolog
implementation).

Actual behaviour: gprolog answers "yes", without binding anything to T
(it remains an unbound variable).

The problem seems to be specific to the case of there being no match;
with the comparable

phrase([1], [1,2], T).

gprolog will produce the output of "T=[2]" and "yes" (the expected
output), and will not suggest a second solution with T unbound.

It's also specific to the use of phrase/3 for evaluating DCG literals
directly; using the --> operator to give a name to the grammar
consisting only of [2], then executing that grammar (whether directly or
with phrase/3), produces the correct results.

phrase/2 seems to have the same buggy behaviour as phrase/3 (probably
because it's implemented as calling phrase/3 behind the scenes).

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: gprolog 1.4.5.0-3
ProcVersionSignature: Ubuntu 5.4.0-84.94-generic 5.4.133
Uname: Linux 5.4.0-84-generic x86_64
ApportVersion: 2.20.11-0ubuntu27.20
Architecture: amd64
CasperMD5CheckResult: skip
CurrentDesktop: X-Cinnamon
Date: Wed Oct  6 08:42:51 2021
ExecutablePath: /usr/lib/gprolog/bin/gprolog
InstallationDate: Installed on 2019-11-11 (694 days ago)
InstallationMedia: Ubuntu 18.04.3 LTS "Bionic Beaver" - Release amd64 (20190805)
SourcePackage: gprolog
UpgradeStatus: Upgraded to focal on 2020-10-02 (368 days ago)

** Affects: gprolog (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug focal third-party-packages

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1946197

Title:
  gprolog builtin phrase/3 incorrectly succeeds when matching constant
  lists

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gprolog/+bug/1946197/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to