From 3ad55f8035b9c93d81b57c5b7e6afdc3ef5e20a9 Mon Sep 17 00:00:00 2001 From: "J.J. Tolton" Date: Tue, 21 Oct 2025 19:06:30 -0400 Subject: [PATCH 1/5] Add support for binary quad syntax (Goal ?- Answer) This commit adds support for the binary quad test syntax alongside the existing monadic quad syntax. Previously, Scryer Prolog only supported: ?- my_pred(X). X = value. With this change, it now also supports the more concise binary format: my_pred(X) ?- X = value. The loader now recognizes and skips binary quad terms (Goal ?- Answer) during file loading, preventing them from being compiled as regular clauses. This eliminates the 'permission_error(modify,static_procedure)' errors that occurred when the binary operator attempted to define clauses for built-in operators like =/2. Both syntaxes can coexist in the same file and are handled by external test frameworks that process these quad annotations. --- src/loader.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/loader.pl b/src/loader.pl index 445cb81a8..bde38efef 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -215,6 +215,8 @@ instantiation_error(load/1) ; Term = (?- _Query) -> devour_answer_descriptions(Stream, Evacuable) + ; Term = (_ ?- _Answer) -> + load_loop(Stream, Evacuable) ; LineNum is LinesRead + 1, warn_about_singletons(Singletons, LineNum), compile_term(Term, Evacuable), From 513346380b7b7f09e23ec56810d1ad28614e4fe5 Mon Sep 17 00:00:00 2001 From: "J.J. Tolton" Date: Tue, 21 Oct 2025 19:07:35 -0400 Subject: [PATCH 2/5] Define ?- as an infix operator (xfx, 1200) for binary quad syntax To support the binary quad syntax (Goal ?- Answer), we need ?- to be recognized as an infix operator in addition to its existing prefix form. This mirrors how :- is defined as both prefix and infix, allowing it to be used for both directives (:- directive) and clauses (Head :- Body). Now ?- can be used for: - Prefix form (traditional): ?- query. - Infix form (binary quads): goal ?- answer. --- src/parser/ast.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 9effb51eb..aa3c2f425 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -412,6 +412,7 @@ pub fn default_op_dir() -> OpDir { op_dir.insert((atom!(":-"), Fixity::In), OpDesc::build_with(1200, XFX)); op_dir.insert((atom!(":-"), Fixity::Pre), OpDesc::build_with(1200, FX)); + op_dir.insert((atom!("?-"), Fixity::In), OpDesc::build_with(1200, XFX)); op_dir.insert((atom!("?-"), Fixity::Pre), OpDesc::build_with(1200, FX)); op_dir.insert((atom!(","), Fixity::In), OpDesc::build_with(1000, XFY)); From 11f47c1aeba511e1079448aa502a65016a099bcb Mon Sep 17 00:00:00 2001 From: "J.J. Tolton" Date: Tue, 21 Oct 2025 20:02:49 -0400 Subject: [PATCH 3/5] Fix binary quad syntax support in loader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added binary quad check in devour_answer_descriptions - Binary quads with format "Label" ?- Query followed by answer lines are now properly recognized and their answers ignored - Fixes issue where answer descriptions were being compiled as facts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/loader.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/loader.pl b/src/loader.pl index bde38efef..3e74a8163 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -215,8 +215,8 @@ instantiation_error(load/1) ; Term = (?- _Query) -> devour_answer_descriptions(Stream, Evacuable) - ; Term = (_ ?- _Answer) -> - load_loop(Stream, Evacuable) + ; Term = (_ ?- _Query) -> + devour_answer_descriptions(Stream, Evacuable) ; LineNum is LinesRead + 1, warn_about_singletons(Singletons, LineNum), compile_term(Term, Evacuable), @@ -232,6 +232,8 @@ instantiation_error(load/1) ; Term = (?- _Query) -> devour_answer_descriptions(Stream, Evacuable) + ; Term = (_ ?- _Query) -> + devour_answer_descriptions(Stream, Evacuable) ; answer_description(Term) -> devour_answer_descriptions(Stream, Evacuable) ; warn_about_singletons(Singletons, LinesRead), From b92cad65998d97afd8aee6ef0859751c1cb94bdf Mon Sep 17 00:00:00 2001 From: "J.J. Tolton" Date: Tue, 21 Oct 2025 22:56:04 -0400 Subject: [PATCH 4/5] Lower precedence of infix ?- operator to 1199 to avoid conflicts with prefix directives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures that prefix ?- (directives) at precedence 1200 takes priority over infix ?- (dyadic quads) at precedence 1199, preventing parsing ambiguities. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/parser/ast.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/ast.rs b/src/parser/ast.rs index aa3c2f425..c1e4d2367 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -412,8 +412,8 @@ pub fn default_op_dir() -> OpDir { op_dir.insert((atom!(":-"), Fixity::In), OpDesc::build_with(1200, XFX)); op_dir.insert((atom!(":-"), Fixity::Pre), OpDesc::build_with(1200, FX)); - op_dir.insert((atom!("?-"), Fixity::In), OpDesc::build_with(1200, XFX)); - op_dir.insert((atom!("?-"), Fixity::Pre), OpDesc::build_with(1200, FX)); + op_dir.insert((atom!("?-"), Fixity::Pre), OpDesc::build_with(1200, FX)); // Prefix first (directives) + op_dir.insert((atom!("?-"), Fixity::In), OpDesc::build_with(1199, XFX)); // Infix lower precedence (dyadic quads) op_dir.insert((atom!(","), Fixity::In), OpDesc::build_with(1000, XFY)); op_dir From 8d3fade382ed9b383fbb3fd4ded62a5f8443e4aa Mon Sep 17 00:00:00 2001 From: "J.J. Tolton" Date: Thu, 23 Oct 2025 00:39:34 -0400 Subject: [PATCH 5/5] Revert to priority 1200 for both ?- operators This reverts the precedence change, setting both prefix and infix ?- operators back to 1200 to match the :- operator definition. --- src/parser/ast.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/ast.rs b/src/parser/ast.rs index c1e4d2367..aa3c2f425 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -412,8 +412,8 @@ pub fn default_op_dir() -> OpDir { op_dir.insert((atom!(":-"), Fixity::In), OpDesc::build_with(1200, XFX)); op_dir.insert((atom!(":-"), Fixity::Pre), OpDesc::build_with(1200, FX)); - op_dir.insert((atom!("?-"), Fixity::Pre), OpDesc::build_with(1200, FX)); // Prefix first (directives) - op_dir.insert((atom!("?-"), Fixity::In), OpDesc::build_with(1199, XFX)); // Infix lower precedence (dyadic quads) + op_dir.insert((atom!("?-"), Fixity::In), OpDesc::build_with(1200, XFX)); + op_dir.insert((atom!("?-"), Fixity::Pre), OpDesc::build_with(1200, FX)); op_dir.insert((atom!(","), Fixity::In), OpDesc::build_with(1000, XFY)); op_dir