Releases: yuce/pyswip
v0.3.2
Installing
If you have SWI-Prolog installed, it's just:
pip install pyswip==v0.3.2
See PySwip Getting Started for detailed instructions.
Documentation
Find the documentation for this version here.
Changes
- The minimum required Python version is 3.9
- Introduced
pyswip.easy.module
function and deprecatedpyswip.easy.newModule
function. - Introduced
pyswip.prolog.Prolog.register_function
method and deprecatedpyswip.easy.registerForeign
function.
New Features
Python to Prolog Value Exchange via String Interpolation
Added support for value exchange from Python to Prolog using string interpolation in Prolog.assertz
, Prolog.asserta
, Prolog.retract
and Prolog.query
methods.
See the documentation on String Interpolation from Python to Prolog.
Example Modules
More information is in the Introducing the Examples Package note.
v0.3.1
Installing
If you have SWI-Prolog installed, it's just:
pip install pyswip==v0.3.1
See PySwip Getting Started for detailed instructions.
Documentation
Find the documentation for this version here.
Breaking Changes
Mandatory Keyword Arguments in Prolog Class
Some keyword arguments such as catcherrors
used to be passable as positional arguments.
For instance the following was valid:
Prolog.assertz("big(airplane)", False)
Starting with v0.3.1, it is mandatory to pass arguments such as catcherrors
as keyword arguments:
Prolog.assertz("big(airplane)", catcherrors=False)
Enhancements
Prolog.consult
Tilde character in paths are expanded to the user home directory
Prolog.consult("~/my_files/hanoi.pl")
# consults file /home/me/my_files/hanoi.pl
Both strings and pathlib.Path objects are allowed as paths
from pathlib import Path
Prolog.consult(Path("myfile.pl"))
# equivalent to:
Prolog.consult("myfile.pl")
Added relative_to
keyword argument
relative_to
keyword argument makes it easier to construct the consult path.
This keyword is no-op, if the consult path is absolute.
If the given relative_to
path is a file, then the consult path is updated to become a sibling of that path.
Assume you have the /home/me/project/facts.pl
that you want to consult from the run.py
file which exists in the same directory /home/me/project
.
Using the built-in __file__
constant which contains the path of the current Python file , it becomes very easy to do that:
# in run.py
Prolog.consult("facts.pl", relative_to=__file__)
If the given relative_path
is a directory, then the consult path is updated to become a child of that path.
project_dir = "~/projects"
Prolog.consult("facts1.pl", relative_to=project_dir)
Prolog.consult("facts2.pl", relative_to=project_dir)
Symbolic links are not yet supported yet.
Prolog.dynamic
Updated Prolog.dynamic
to accept one ore more terms:
Prolog.dynamic("mother/1", "father/1")
v0.3.0
Installing
If you have SWI-Prolog installed, it's just:
pip install pyswip==v0.3.0
See PySwip Getting Started for detailed instructions.
Changes
Changes since v0.2.10:
- Improve list representations, unicode support and multiple threading usage, see: 97. Contributed by Guglielmo Gemignani.
- Added PL_STRINGS_MARK to getAtomChars, fixes 102. Contributed by Vince Jankovics.
- Backwards compatibility for Python 2 64bit, see: 104. Contributed by Tobias Grubenmann.
- Improved handling of lists, nested lists, strings, and atoms. see: 112. Contributed by Tobias Grubenmann.
- Fixes for changed constants, see: 125. Contributed by Arvid Norlander.
- Refactored SWI-Prolog discovery commit
- Dictionary support, see: commit. Contributed by Max Peltzer.
- Check
PILLIBSWIPL
environment variable for thelibswipl
library path 145. Contributed by Jan Wielemaker. - Avoid AttributeError with PL_version_info in swipl <= 8.4.2 154. Contributed by Jan DestyNova.
- Added hardcoded path for
libswipl.so
43. Contributed by Kumar Abhinav. - Fixed not finding swipl lib file when there are multiple options 153. Contributed by AdiHarif.