Add dyadic quad syntax support
Summary
This PR adds support for dyadic quad syntax to Scryer Prolog's loader, enabling test specifications with labeled queries.
Motivation
This is inspired by Ulrich Neumerkel's quad notation for Prolog testing:
- https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length_quad.pl
- See also: https://github.com/jjtolton/quads for a working implementation
Changes
1. Parser (src/parser/ast.rs)
- Added infix operator definition for
?-(xfx, 1200) - Allows parsing of dyadic quad syntax:
Label ?- Query
2. Loader (src/loader.pl)
- Modified
load_loopto recognize dyadic quads(_ ?- _Query) - Modified
devour_answer_descriptionsto handle dyadic quads recursively - Dyadic quads and their answer descriptions are now properly skipped during loading
Syntax Supported
Monadic quads (already supported):
?- my_append([1,2], [3,4], Xs).
Xs = [1,2,3,4].
Dyadic quads (NEW):
"Test append" ?- my_append([1,2], [3,4], Xs).
Xs = [1,2,3,4].
Testing
Tested with the quads package: https://github.com/jjtolton/quads
Example files that now load correctly:
- Dyadic quads with string labels followed by answer descriptions
- Mixed monadic and dyadic quads in the same file
Important Note
This is a proof-of-concept implementation only. The author acknowledges that someone more experienced with Scryer Prolog internals should review and potentially reimplement this functionality properly. This PR serves to demonstrate that the feature is feasible and useful.
Related
- Quads package with dyadic quad support: https://github.com/jjtolton/quads
- Original inspiration: Ulrich Neumerkel's work on quad notation
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]
I don't think having ?- as an infix operator by default is a good idea. One very good point of Scryer Prolog in my opinion is that is comes with just the ISO Prolog operators by default. You can add support for binary quads without the operator just fine, and users can define the operator themselves if they want.
I don't think having
?-as an infix operator by default is a good idea. One very good point of Scryer Prolog in my opinion is that is comes with just the ISO Prolog operators by default. You can add support for binary quads without the operator just fine, and users can define the operator themselves if they want.
Oh yeah? Then how do you explain this: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length_quad.pl
(for the record I agree in the sense that I would've done this entirely as a package, but there's no way that I know of to support dyadic quads with an external "patch" to scryer, need to modify source directly as far as I know. Maybe it could be done with a crate?)
Could you give an example where such an ambiguity might arise? Typically, there is a problem with infix versus postfix. That's why there is such a restriction in 6.3.4.3. See also Note 4.
I have no immediate evidence it would be a problem but the situation that concerns me is some scenario where
:- use_module(library(lists)).
?- X=1.
X=1.
could be interpreted as
((:- use_module(library(lists))) ?- X=1)
although as I am typing this I realize that the . would fairly definitively prevent that from occurring. :thinking:
Perhaps overly defensive. I should more thoroughly review the priorities given to operators.
Perhaps overly defensive. I should more thoroughly review the priorities given to operators.
Your example needs to be modified a bit. By "forgetting" an end-dot for a fact, we then get:
fact(nimporte) /* forgotten dot */
?- true.
true.
On the other hand, the lowered priority of the infix ?- now leads to the following confusions:
a :-
b,
c /* forgotten dot */
?- true.
What would be in fact more important is a better indication of syntax errors (#302).
And in general, I am not too happy that these quad-discussions start now, because there is a significant backlog w.r.t. digit separators and the double bar notation. As long as these are not fixed, it does not make much sense to look into further steps for quads.
And in general, I am not too happy that these quad-discussions start now, because there is a significant backlog w.r.t. digit separators and the double bar notation. As long as these are not fixed, it does not make much sense to look into further steps for quads.
Is there more of this backlog? Do you mean what is one the Scryer issues board or something else?
Is there more of this backlog? Do you mean what is one the Scryer issues board or something else?
Currently, I am looking just at digit separators. That is, I am waiting currently for updates.