meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
nlessa 2020-04-11T19:04:41.118600Z

Hi! Is there a restrinction using with operator in a defsyntax? I tried something like this:

(me/defsyntax g1 [] `(me/with [%e-entidade (me/or (= e (me/pred unificador? ?e))
                                                  (= (me/pred unificador? ?e) e))
                               %a-atributo (me/or (= a (me/pred keyword? ?a))
                                                  (= (me/pred keyword? ?a) a))]
                              [%e-entidade %a-atributo]))
And using in
(def test
  (ms/rewrite
    (g1) [?e ?a]
I get an
Syntax error macroexpanding meander.match.epsilon/find 
with binding form must be a simple symbol the name of which begins with "%"
But if copy-paste tge code of g1 runs fine
(def test-2
  (ms/rewrite
   (me/with [%e-entidade (me/or (= e (me/pred unificador? ?e))
                                (= (me/pred unificador? ?e) e))
             %a-atributo (me/or (= a (me/pred keyword? ?a))
                                (= (me/pred keyword? ?a) a))]
            [%e-entidade %a-atributo]) [?e ?a]))
Is it a restriction of defsyntax using with or am I making a mistake?

noprompt 2020-04-11T21:46:58.120200Z

@nlessa This is because of the back tick:

(meander.epsilon/with [meander.dev.zeta/%e-entidade (meander.epsilon/or ,,,)
                    ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       ]
  ,,,)
To make this work you will need to use # suffixed symbol names like this
`(me/with [%e-entidade# (me/or ,,,)
           ,,,]
   ,,,))
;; =>
(meander.epsilon/with [%e-entidade__25097__auto__ (meander.epsilon/or ,,,)]
  ,,,)

💯 1
noprompt 2020-04-11T21:51:19.121400Z

(me/defsyntax foo [x]
  `(me/with [%foo ~x] ;; <-- Broken, %foo needs to be %foo#
     %foo))

(me/rewrite 1 (foo ?x) ?x)
;; =>
;; with binding form must be a simple symbol the name of which begins
;; with "%"
;; {:invalid-binding meander.dev.zeta/%foo,
;;  :form (meander.epsilon/with [meander.dev.zeta/%foo ?x]
;;          meander.dev.zeta/%foo)}

(me/defsyntax foo [x]
  `(me/with [%foo# ~x] ;; <-- Fixed
     %foo#))

(me/rewrite 1 (foo ?x) ?x)
;; => 1

💯 1
noprompt 2020-04-11T21:54:23.123300Z

The ex-info for this error should probably have a :syntax-trace and maybe a hint or something which offers a little guidance.

noprompt 2020-04-11T22:00:03.125Z

I do have something for

Unable to resolve symbol: ?y in this context
sorts of errors that occasionally come up when using rewrite. A rule like
(:foo ?x)
  (:bar ?y)
will produce a error like
There are variables on the right which do not appear on the left.
   {:vars-missing-on-left #{?y},
    :left-form (:foo ?x),
    :left-meta {:line 1295, :column 3},
    :right-form (:bar ?y),
    :right-meta {:line 1296, :column 3}}

💯 1
1
nlessa 2020-04-12T15:25:23.125600Z

Thank you very much! It's all working! Really amazed with Meander.

🙂 1