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.py

15 lines
360 B
Python
Raw Normal View History

2010-06-01 00:33:32 +01:00
from pyswip import Prolog, registerForeign, Atom
def atom_checksum(*a):
if isinstance(a[0], Atom):
r = sum(ord(c)&0xFF for c in str(a[0]))
a[1].value = r&0xFF
return True
else:
return False
p = Prolog()
registerForeign(atom_checksum, arity=2)
print list(p.query("X='Python', atom_checksum(X, Y)", catcherrors=False))