Skip to content

Fix hyphenated predicate names breaking tabled/1 - #220

Open
Aryam-21 wants to merge 1 commit into
trueagi-io:mainfrom
Aryam-21:fix/lib-tabling-hyphen
Open

Aryam-21 wants to merge 1 commit into
trueagi-io:mainfrom
Aryam-21:fix/lib-tabling-hyphen

Conversation

@Aryam-21

@Aryam-21 Aryam-21 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Reproducing the bug (before this fix)

Run this against the unpatched lib_tabling.metta:

!(import! &self (library lib_tabling))
(= (count-atom $x $y) True)
!(tabled (count-atom $x $y))

This fails with:

ERROR: Domain error: `tabled_mode` expected, found `count`

Root cause: tabled/1 embeds the predicate name unquoted in the
generated :- table Name/Arity. directive. Since - is a Prolog
infix operator, count-atom gets parsed as count - atom instead
of as an atom.

Fix

Wrap the name in single quotes before embedding it, so it's read
as one atom regardless of its characters:

:- table 'count-atom'/3.

Verified

?- atomics_to_string([":- table '", "count-atom", "'/", "3", "."], Code),
   open_string(Code, S), load_files(user, [stream(S)]).
Code = ":- table 'count-atom'/3."   % succeeds, no error

Also confirmed end-to-end via sh run.sh examples/tabling_hyphen.metta
tabled((count-atom $x $y)) now loads with no error.

tabled/1 built the table/1 directive by concatenating the raw
predicate name unquoted, e.g. ':- table count-atom/3.'. Since '-'
is a Prolog infix operator, unquoted hyphenated names (like
count-atom) are misread as an arithmetic expression instead of
an atom, raising a 'tabled_mode' domain error.

Fixes this by embedding the name as a quoted atom
(':- table 'count-atom'/3.') and simplifying the implementation
to a single translatePredicate call instead of three.
@Aryam-21
Aryam-21 force-pushed the fix/lib-tabling-hyphen branch from c5d603d to fb55255 Compare August 28, 2026 05:15
@Aryam-21 Aryam-21 changed the title tabled/1: lock in hyphenated predicate name handling Fix hyphenated predicate names breaking tabled/1 Aug 28, 2026
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

Successfully merging this pull request may close these issues.

1 participant