Fork me on GitHub
#datascript
<
2017-11-04
>
tavistock18:11:12

given the rules:

[[(coords ?pos ?x ?y)
     [?pos :position/x ?x]
     [?pos :position/y ?y]]

    [(near ?i1 ?i2)
     [(inc ?i1) ?i2]]
    [(near ?i1 ?i2)
     [(dec ?i1) ?i2]]

     [(neighbor ?pos1 ?pos2)
     (coords ?pos1 ?x1 ?y1)
     (near ?x1 ?x2)
     (near ?y1 ?y2)
     [?pos2 :position/x ?x2]
     [?pos2 :position/y ?y2]]

    [(connected ?pos1 ?pos2 ?via)
     (neighbor ?pos1 ?via)
     (neighbor ?pos2 ?via)]
I can’t get connected to return x and y’s that are in line with it to work correctly. eg. [2 2] should return [[4 4] [0 0]…] whereas [4 2] returns [[6 2] [2 0]…]. what am i doing wrong?

Niki18:11:02

What result do you get vs what do you expect?

tavistock19:11:08

i expect the first image to have [4 4] and [0 0] highlighted in green in addition to what is there, but the results i get are missing those 2 values.

Niki19:11:09

Can you post the full database you're using?

Niki19:11:20

better if you copy all that & full DB structure/content into github issue

tavistock19:11:54

idk if it’s an issue it might just be my code

Niki19:11:55

thanks, I’ll take a look

Niki19:11:26

yeah I can’t spot any immediate problems, might as well be a bug

tavistock19:11:37

i’ll write an issue later, when i get some time to make that gist.

tavistock19:11:06

a semi related question, does rule body order matter

[(rule1 ?a)
 (subrule1 ?a)
 (subrule2 ?a)]

[(rule2 ?a)
(subrule2 ?a)
(subrule1 ?a)]
should rule1 and rule2 be equivalent?

Niki19:11:31

on the other hand, there’s always room for some bugs :)

Niki19:11:44

recursive rules is one of the most complicated parts in DS

tavistock19:11:46

I’m sorry i phrased my question weird, yes rule1 and rule2 are equal or yes rule order matters?

Niki19:11:14

yes they should be equal

tavistock19:11:18

even if they have function rules like [(fn ?a ?b) ?c]?

Niki19:11:05

for function rules there’s just one limitation: all arguments should be bound at the call place

Niki19:11:24

so you can’t have ?a or ?b bound after fn call, only before

Niki19:11:36

but you can make additional rules after the fn call of course

tavistock21:11:02

@tonsky https://github.com/tonsky/datascript/issues/239 and I didn’t mention it but thanks for responding