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?@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 ,,,)]
,,,)
(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
The ex-info
for this error should probably have a :syntax-trace
and maybe a hint or something which offers a little guidance.
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}}
Thank you very much! It's all working! Really amazed with Meander.