I am pleased to announce the 0.1.3 version of PySWIP. PySWIP is a GPL'd Python - SWI-Prolog bridge which enables querying SWI-Prolog in your Python programs. PySWIP includes both an (incomplete) SWI-Prolog foreign language interface and a utity class that makes it easy querying SWI-Python. Since it uses SWI-Prolog as a shared library and ctypes to access it, PySWIP doesn't require compilation to be installed. This version breaks the compatibility with previous versions. Example: >>> from pyswip.prolog import Prolog >>> prolog = Prolog() >>> prolog.assertz("father(michael,john)") [{}] >>> prolog.assertz("father(michael,gina)") [{}] >>> list(prolog.query("father(michael,X)")) [{'X': 'john'}, {'X': 'gina'}] >>> for soln in prolog.query("father(X,Y)"): ... print soln["X"], "is the father of", soln["Y"] ... michael is the father of john michael is the father of gina Foreign Functions Example: Since version 0.1.3 of PySWIP, it is possible to register a Python function as a Prolog predicate through SWI-Prolog's Foreign Function Interface. Here's an example: from pyswip.prolog import Prolog from pyswip.easy import registerForeign, getAtomChars def hello(t): print "Hello,", getAtomChars(t) return True hello.arity = 1 registerForeign(hello) prolog = Prolog() prolog.assertz("father(michael,john)") prolog.assertz("father(michael,gina)") list(prolog.query("father(michael,X), hello(X)")) Outputs: Hello, john Hello, gina Requirements: * Python 2.3 and higher. * ctypes 0.9.9.9 and higher. * SWI-Prolog 5.6.x and higher (most probably other versions will also work). * libpl as a shared library. * Works on Linux and Win32, should work for all POSIX. Changes since version 0.1.2: * Renamed `pyswip/util.py` to `pyswip/prolog.py`. * New module `pyswip.easy`. * Now it is possible to register a Python function as a Prolog predicate through SWI-Prolog's Foreign Function Interface. * Additions to the core library. * Added example, *register foreign* which shows how to register a Python function as an SWI-Prolog predicate. * Added example, *Towers of Hanoi* PySWIP homepage is at: http://code.google.com/p/pyswip Downloads at: http://code.google.com/p/pyswip/downloads/list Discussion Group is at: http://groups.google.com/group/pyswip Regards, Yuce Tekol yucetekol [at] gmail [dot] com>
participants (1)
-
yuce