-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestProlog.py
48 lines (41 loc) · 1.22 KB
/
testProlog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
__author__ = 'giodegas'
from pysicstus import SicstusProlog, PrologSystem
def main():
# Example 1
sp = SicstusProlog('test1')
sp.spawn('prolog/testProgram.pro', 'testGoal') # non blocking
sp.waitFor('OK')
ans = sp.ask('friend(pippo,pluto)')
print(ans)
if sp.ask('friend(pippo,pluto)'):
print('I know that pippo and pluto are friends')
else:
print('Apparently, pippo does not know pluto.')
print("Is Prolog alive?", sp.isAlive())
print(isinstance(sp, PrologSystem))
# Example 2
sp2 = SicstusProlog('test2')
sp2.spawn()
sp2.consultFile('prolog/testProgram.pro', 'test', debug=True)
print(sp2.ask('friend(pippo,pluto)'))
# Example 3
sp3 = SicstusProlog('test3')
sp3.spawn()
prologProgram = '''
x.
y.
couple(X, Y) :- X, Y.
'''
sp3.consult(prologProgram)
print(sp3.ask('x'))
print(sp3.ask('couple(x,y)'))
print(sp3.ask('couple(x,z)'))
print(sp3.ask('alfa'))
# Example 4
sp4 = SicstusProlog('tcpLogger')
sp4.spawn()
sp4.consultFile('prolog/testSocket.pro')
sp4.ask("writeTcp('test tcp 2')")
if __name__ == "__main__":
main()