Fork me on GitHub
#meander
<
2020-04-28
>
nlessa16:04:49

Hi! I am not understanding why something like this works

(ms/rewrite
  (me/with [%e-entidade (me/or (= e (me/pred symbol? ?e))
                               (= (me/pred symbol? ?e) e))
            %a-atributo (me/or (= a (me/pred keyword? ?a))
                               (= (me/pred keyword? ?a) a))
            %v-valor (me/or (= v (me/pred symbol? ?v))
                            (= (me/pred symbol? ?v) v))
            %v-args (me/or (me/pred symbol? ?v)) 
            %v-teste-unario ((me/pred function? !funcao-unaria) !param-function-unaria)
            %operador-binario (me/pred #{'< '> '<= '>= 'not=} !funcao-binaria)
            %v-teste-binario (%operador-binario %v-args !param-function-binaria)
            %v-teste-funcao (me/or %v-teste-unario %v-teste-binario)
            %v-expression (me/or %v-valor %v-teste-unario %v-teste-binario)]
           [%e-entidade %a-atributo %v-valor . %v-teste-funcao ..1]) :ok)
but if I add any other params in the the (me/or of %v-args, eg,
%v-args (me/or (me/pred symbol? ?v) a-symbol) 
I get an Unable to resolve symbol: ?v in this context What am I missing? Thanks in advance!

jimmy16:04:31

@nlessa Definitely looks like a bug. Will try to find some time today to dig into it.

jimmy17:04:16

I am a little confused as to what you are trying to accomplish though. Do you have an example of the data your are matching on?

jimmy17:04:36

Those = signs are not going to be doing what I think you want them to do.

jimmy17:04:55

So while I might be able to find the bug, I want to make sure you can accomplish your task as well.

nlessa17:04:48

Thanks, @jimmy! The symbols = appears in the grammar that is being rewrited. It's been working fine, only with this little problem with the me/or. The use case I am working is a transformation from rules expressed in Clara Rules to datalog clauses. Meander worked very well! I faced only this and another strange problem (but with workaround) . I will post later here the other problem I found.

jimmy17:04:44

Okay, cool. Just wanted to make sure that the = signs were meant to be literals.

jimmy17:04:48

Also great to hear that it is working for you. Interesting to see a transformation from clara to datalog. Hopefully we can help fix those remaining issues.

jimmy17:04:16

Okay so the fact that you get the error you do is a bug. But for %v-args (me/or (me/pred symbol? ?v)) if you want something else in the or you need to make sure it has ?v in it.

👍 4
jimmy17:04:46

If you add a pattern that includes ?v there you should be fine. We are clearly failing to detect that problem correctly though and so we generate bad code.

nlessa17:04:07

Ah, ok, understood!

jimmy17:04:02

@noprompt Just fyi. Looks like we consider ?v bound already because of %v-valor and so argument-lvrs is empty. https://github.com/noprompt/meander/blob/b2a6ab1135f3bf3be3abf2f113930c4ffec71f04/src/meander/match/check/epsilon.cljc#L154-L187

noprompt17:04:32

@jimmy Thanks for taking a look. Do you have a patch in mind or did you want me to take it from here?

noprompt17:04:56

I’m sure fixing this will probably fix other instances of this problem.

noprompt17:04:20

(I’ve encountered it once in the last couple months but didn’t have a chance to properly look into it.)

jimmy17:04:37

I haven't had a chance to think of a fix. Need to familiarize myself with that code. Just wanted to dump the little bit I found here.

noprompt17:04:04

Okay, cool. This is perfect. It saves a ton of time. 🙂