core-logic

2018-09-14T12:58:29.000100Z

agreed. I think the confusion is also perhaps because conj in microkanren is not clojure’s conj. It’s conj^2 which is conjunctive (`and`)… likewise disj in microkanren is disjuntive i.e. or. Not sure if core.logic ports these functions directly either, as they’re part of microkanren… and perhaps not minikanren… would need to look.

2018-09-14T12:59:37.000100Z

I don’t have the papers in front of me though so could also be wrong…

risto 2018-09-14T20:43:11.000100Z

i know -o is a relation, how those lazy streams and conj/disj are implremented key in making sure appendo doesnt recurse forever and blow the stack

2018-09-14T20:46:41.000100Z

thats not true, the fact that appendo does case analysis and only one of the cases can be true at a time, and induction on the first argument (the first argument is smaller on every recursvie call) is what guarantees termination

2018-09-14T20:48:20.000100Z

ah, the blowing the stack

2018-09-14T20:49:03.000100Z

that is because in your implementation you are doing the recursive call to appendo when appendo is called, not as the logic program is running

2018-09-14T20:49:19.000100Z

doing that switch is tricky in a language without macros

2018-09-14T20:50:08.000100Z

in my go implementation I had a special goal constructor for making recursive calls to make that work

risto 2018-09-14T20:51:45.000100Z

yeah

risto 2018-09-14T20:52:03.000100Z

there's something key with that which im messing up

2018-09-14T20:52:30.000100Z

it doesn't have to do with the stream implementation

2018-09-14T20:53:12.000100Z

it has to do with goal construction, which without macros, you can't delay the recursive call until you know if you have to do it

2018-09-14T20:54:18.000100Z

so if or or disj is a regular function, all of its arguments must be evaluated before it is called, and if one of those is a recursive call, boom

risto 2018-09-14T20:54:58.000100Z

yeah, it has to delay the goal somehow

2018-09-14T20:56:41.000100Z

so my Call goal constructor in go would look something like (fn [goal & args] (fn [package] ((apply goal args) package))) in clojure

2018-09-14T21:01:20.000100Z

which has a similar structure to what conde in core.logic expands to https://github.com/clojure/core.logic/blob/master/src/main/clojure/clojure/core/logic.clj#L1175-L1183