Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swipl DCG does not appear to function #131

Open
salamander-eng opened this issue Oct 15, 2021 · 1 comment
Open

Swipl DCG does not appear to function #131

salamander-eng opened this issue Oct 15, 2021 · 1 comment

Comments

@salamander-eng
Copy link

This seems to work when a file is consulted, but does not appear to work when utilized via assert:
Simplest possible example:

as --> [].
as --> [a], as.
?- phrase(as,[a,a,X,a]).
X = a.

If the DCG is described in a file and p.consult("dcgtest.pl") used, this works as expected:

for r in p.query("phrase(as,[a,X,a,a])"):
print(r)

If we try to assert instead, things do not appear to be parsing correctly

p.assertz("as --> []")
p.assertz("as --> [a], as")

yields

PrologError: Caused by: 'phrase(as,[a,X,a,a])'. Returned: 'error(existence_error(procedure, /(as, 2)), context(:($dcg, /(call_dcg, 3)), Variable(76)))'.

I need to generate and insert the DCG from the python side. Is there a way to accomplish this that I am not understanding ?

@salamander-eng
Copy link
Author

Part of this issue is with the way that swipl implements assertz and will fail when tested against swipl using this construct. This could probably be fixed within pyswip by using the [user] pseudo file instead of asserta/asserz mechanism, but that seems a lot of work for a corner case.

To work around this problem use the dcg translation mechanism directly. To test the above code, try the construct

?- dcg_translate_rule((as --> []),T),assertz(T).
?- dcg_translate_rule((as --> [a], as),T),assertz(T).
?- phrase(as,X).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant