This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/pyswip/examples/register_foreign_simple.py

21 lines
503 B
Python
Raw Normal View History

2010-06-01 00:33:32 +01:00
# -*- coding: utf-8 -*-
# Demonstrates registering a Python function as a Prolog predicate through SWI-Prolog's FFI.
from pyswip.prolog import Prolog
from pyswip.easy import registerForeign, getAtomChars
def hello(t):
print "Hello,", t
hello.arity = 1
def main():
registerForeign(hello)
prolog = Prolog()
prolog.assertz("father(michael,john)")
prolog.assertz("father(michael,gina)")
list(prolog.query("father(michael,X), hello(X)"))
if __name__ =="__main__":
main()