Open
Description
I define friend relation as follows. It got RecursionError
, how do you avoid of it?
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
from kanren import *
class DemoRelation(Relation):
def __call__(self, *args, **kwargs):
print('pair', *args)
super(DemoRelation, self).__call__(*args, **kwargs)
pair = DemoRelation()
facts(pair, ("Liao", "Lufei"))
facts(pair, ("Liao", "Wang"))
def friend(x,z):
print(x, z, 'friend?')
y=var()
return conde((pair(x, z),), (pair(x,y), pair(y,z)), (friend(z, x),))
x=var()
res =run(1, x, friend(x, "Liao"))
print(res)
Metadata
Metadata
Assignees
Labels
No labels