Skip to content

Unify a variable with a compound term - #200

Open
rmanhaeve wants to merge 1 commit into
yuce:masterfrom
rmanhaeve:unify-compound-terms
Open

rmanhaeve wants to merge 1 commit into
yuce:masterfrom
rmanhaeve:unify-compound-terms

Conversation

@rmanhaeve

@rmanhaeve rmanhaeve commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

A variable cannot be unified with a term built through PySwip:

>>> from pyswip.easy import Functor, Variable
>>> Variable().unify(Functor("g", 1)(1))
TypeError: Cannot unify Variable(23) with value <pyswip.easy.Term object ...>
    due to the value unknown type <class 'pyswip.easy.Term'>

Functor.__call__ returns a Term, but Variable._fun has a branch for an
atom, a string, an integer, a boolean, a float and a list, and none for a
term. A foreign predicate therefore has no way to return a compound term,
only an atom or a list.

This puts the term into a term reference and unifies that, the way a list is
already handled. PL_unify is added to the imports. The regression test
registers a foreign predicate that returns g(1), and fails before the
change with the TypeError above.

tests/test_issues.py::TestIssues::test_issue_15 fails on my machine both
before and after, so it looks unrelated.

🤖 Generated with Claude Code

Functor.__call__ returns a Term, but Variable._fun has no branch for one, so
a variable cannot be unified with a term built through PySwip. A foreign
predicate therefore has no way to return a compound term.

Put the term in a term reference and unify that, the way a list is handled.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fie7FW6gwVcPBad7V9m5SM
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