How to write facts based on other facts #67
|
The following code doesn't work as expected because two invocation of Line = Relation()
LengthOf = Relation()
facts(LengthOf, (Line('B', 'C'), 1))
l = var()
run(1, l, LengthOf(Line('B', 'C'), l))Though possible, the workaround is not elegant: g = Line('B', 'C')
facts(LengthOf, (g, 1))
l = var()
run(1, l, LengthOf(g, l))What's the best practice to state facts based on other facts? |
Replies: 1 comment
|
Altogether, this means that the expression More specifically, the goal generated by |
Line(*args)should return a goal object, which is generally a callable that takes miniKanren state objects (i.e. "substitution"/unification mappings) and returns a stream of new states. Those goal objects are chained together using theldisjandlconjoperators (e.g. via the helper functions/aliasesconde,lall,land, etc.) and evaluated byrun.Altogether, this means that the expression
LengthOf(Line(*args), ...)will create a goal that relates a goal to something else; in other words, the result is some sort of "higher-order" relation on the machinery of miniKanren itself (i.e. goals). That's an interesting path to go down, but it might not be what you want.More specifically, the goal …