Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

ERROR: atom_chars/2: Arguments are not sufficiently instantiated

123 views
Skip to first unread message

Ted

unread,
Oct 25, 2023, 1:50:57 AM10/25/23
to pyswip
I am using a macbook pro Apple-M1 running macOS Ventura 13.5.2. 

I have installed

 *  pyswip-0.2.10 
 * swi-prolog version 9.0.4 using Mac Homebrew
 * Python 3.11.4 [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin

I am trying to run the following pyswip instructional example but am the getting errors listed below. I also get the same error which I use pyswip to consult a prolog knowledge base that I know works in the version of swi-prolog that I have.

Any help is supremely appreciated
Thanks!

>>> from pyswip import Prolog
>>> prolog = Prolog()
>>> prolog.assertz("father(michael,john)")

ERROR: atom_chars/2: Arguments are not sufficiently instantiated
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ted/misc/hacking_around/by-jove-rpg/by_jove/.venv/lib/python3.11/site-packages/pyswip/prolog.py", line 140, in assertz
    next(cls.query(assertion.join(["assertz((", "))."]), catcherrors=catcherrors))
  File "/Users/ted/misc/hacking_around/by-jove-rpg/by_jove/.venv/lib/python3.11/site-packages/pyswip/prolog.py", line 126, in __call__
    raise PrologError("".join(["Caused by: '", query, "'. ",
pyswip.prolog.PrologError: Caused by: 'assertz((father(michael,john))).'. Returned: 'error(instantiation_error, context(:(system, /(atom_chars, 2)), _3208))'.

Odane Roberts

unread,
Oct 25, 2023, 7:28:33 AM10/25/23
to pys...@googlegroups.com
Check that all your facts are instantiated , e.g Michael and John 

--
You received this message because you are subscribed to the Google Groups "pyswip" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyswip+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyswip/da343593-8b16-432d-97d3-1d63deb20f3fn%40googlegroups.com.

Ted

unread,
Oct 25, 2023, 3:21:40 PM10/25/23
to pyswip
Thanks Odane. How do I do this?  I thought the code I provided is actually asserting a fact:

  prolog.assertz("father(michael,john)")

Both "michael" and "john" are atoms so there's nothing to instantiate, correct?

Also, I get the same exact error when I try to consult a prolog knowledge base file, which is a different operation from "assertz"

    prolog.consult("my_knowledge_base.prolog")

Thanks again for your assistance, it's much appreciated

Odane Roberts

unread,
Oct 25, 2023, 3:31:26 PM10/25/23
to pys...@googlegroups.com

Try passing the assertion as a list of strings like this: prolog.assertz(["father(michael,john)"])



Also Try specifying the full path to your knowledge base file: prolog.consult("/full/path/to/my_knowledge_base.prolog")


Ted Sandler

unread,
Oct 25, 2023, 3:54:33 PM10/25/23
to pys...@googlegroups.com
Passing the query string wrapped in a list doesn't solve the problem.

>>>  prolog.assertz(["father(michael,john)"])

----> 1 prolog.assertz(["father(michael,john)"])

File ~/misc/hacking_around/by-jove-rpg/by_jove/.venv/lib/python3.11/site-packages/pyswip/prolog.py:140, in Prolog.assertz(cls, assertion, catcherrors)
    138 @classmethod
    139 def assertz(cls, assertion, catcherrors=False):
--> 140     next(cls.query(assertion.join(["assertz((", "))."]), catcherrors=catcherrors))

AttributeError: 'list' object has no attribute 'join'


You received this message because you are subscribed to a topic in the Google Groups "pyswip" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyswip/u72gy2NcFx4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyswip+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyswip/CABy6zKkqtRdby_-FfB7yg8DJGoLffAq%3DV%2BDbHKKKvZ5Ow3PUQw%40mail.gmail.com.

Marco Caspani

unread,
Mar 18, 2024, 7:25:50 AM3/18/24
to pyswip
Hi Ted! Could you solve the issue? I am having the same issue as yours and I cannot find a solution.

Thanks in advance

M

Ted

unread,
Mar 18, 2024, 7:50:29 PM3/18/24
to pyswip
Hi Marco, I switched from using "pyswip" to "swiplserver" version 1.0.2 and that worked for me.
Cheers


yuce

unread,
Oct 7, 2024, 12:33:04 PM10/7/24
to pyswip
I've tested this with PySwip v0.3.0 using SWI-Prolog 9.0.4 and cannot reproduce it.

>> from pyswip import Prolog
>>> prolog = Prolog()
>>> prolog.assertz("father(michael,john)")
>>> list(prolog.query("father(Father, Child)"))

Reply all
Reply to author
Forward
0 new messages