This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-11
Channels
- # announcements (3)
- # aws (3)
- # babashka (79)
- # beginners (105)
- # calva (10)
- # chlorine-clover (22)
- # clj-kondo (12)
- # cljs-dev (39)
- # clojure (52)
- # clojure-europe (1)
- # clojure-spec (15)
- # clojure-uk (12)
- # clojurescript (47)
- # conjure (93)
- # data-science (1)
- # datomic (10)
- # emacs (6)
- # figwheel-main (14)
- # fulcro (30)
- # instaparse (3)
- # kaocha (2)
- # lambdaisland (3)
- # malli (2)
- # meander (6)
- # off-topic (27)
- # pathom (14)
- # perun (1)
- # reagent (15)
- # shadow-cljs (69)
- # slack-help (2)
- # spacemacs (5)
- # test-check (23)
- # vim (9)
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 ,,,)]
,,,)
💯 4
(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
💯 4
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}}
💯 4
4