This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-31
Channels
- # announcements (4)
- # aws (1)
- # babashka (52)
- # beginners (178)
- # boot (4)
- # cider (2)
- # clj-kondo (10)
- # cljs-dev (39)
- # clojure (744)
- # clojure-europe (12)
- # clojure-germany (6)
- # clojure-india (56)
- # clojure-italy (5)
- # clojure-nl (60)
- # clojure-spec (9)
- # clojure-sweden (14)
- # clojure-uk (36)
- # clojuredesign-podcast (6)
- # clojurescript (11)
- # community-development (5)
- # core-async (4)
- # data-science (6)
- # datomic (6)
- # emacs (7)
- # events (4)
- # exercism (33)
- # fulcro (11)
- # funimage (2)
- # graalvm (29)
- # java (1)
- # joker (3)
- # lambdaisland (15)
- # malli (2)
- # meander (55)
- # mid-cities-meetup (1)
- # nrepl (8)
- # observability (4)
- # off-topic (2)
- # pathom (5)
- # re-frame (31)
- # shadow-cljs (73)
- # spacemacs (18)
- # sql (27)
- # test-check (14)
- # testing (1)
- # tools-deps (5)
- # xtdb (13)
Is this a bug?
(m/rewrite {}
{:k (m/seqable !x ..!n)}
{:k [!x ..!n]})
;; => {:k []}
(m/rewrite [{}]
[{:k (m/seqable !x ..!n)} ...]
[{:k [!x ..!n]} ...])
;; => []
@qythium @U06MDAPTP FWIW just wanted to add my 2c that I’ve encountered this and found that using named collectors is usually the ticket in my usage:
(m/rewrite [{}]
[{:k (m/seqable !x ..!n)} ...]
[{:k [!x ..!n]} ...])
=> []
(m/rewrite [{}]
[{:k (m/seqable !x ..!n)} ..!m]
[{:k [!x ..!n]} ..!m])
=> [{:k []}]
To me this seemed logical because I think of …
as disperse everything without context. /shrugThis is the line: https://github.com/noprompt/meander/blob/epsilon/src/meander/substitute/epsilon.cljc#L334
I think I'll just avoid the ..!n
construct entirely for now... it seemed so useful at first but it's just been a source of bugs and headaches 😕
But in this case its not the ..!n
that is the problem its actually the …
in this case.
Its slightly slower to execute a zeta
pattern match but its also much easier to manage and iteratively improve than starting at the lowest level first.
What slightly worries me about Zeta's bootstrapping is that if there are still correctness issues with the epsilon logic that's used to compile it, will that mean that it's all going to be a black box built on a uncertain foundation?
90% of the parser/compiler stuff is built with logic variables. I do use a handful of memory variables but there’s no nesting.
Thats fine. But I hope it gives you confidence know that I’m not trying to cut corners.
The logic makes sense as:
If epsilon
has a bug
And zeta
uses epsilon
to build zeta
Then epsilon
should be patched
🙂
unrelated question, what's the best way of providing "default" values for variables?
(m/rewrite {}
{:k ?v}
{:k ~(or ?v :default)})
this works for logic vars but gives an error on
(m/rewrite [{}]
[{:k !v} ...]
[{:k ~(or !v :default)} ...])
(m/rewrite [{}]
[{:k (m/or !v (m/let [!v :default]))} ...]
[{:k !v} ...])
;; => [{:k nil}]
(me/rewrite [{}]
[{:k (me/or (me/let [!v :default]) !v)} ...]
[{:k !v} ...])
;; =>
[{:k :default}]
(m/rewrite [{:k :exists} {}]
[{:k (m/or (m/let [!v :default]) !v)} ...]
[{:k !v} ...])
;; => [{:k :default} {:k :default}]
You want something like the example I gave
(m/or (m/and nil (m/let [!v :default]))
!v)
(me/rewrite [{} {:k "i have a value"}]
[{:k (me/or (me/and nil (me/let [!v :default])) !v)} ...]
[{:k !v} ...])
;; =>
[{:k :default} {:k "i have a value"}]
You could do
(me/defsyntax default [match p clojure-expr]
`(me/or (me/and ~match (me/let [~p ~clojure-expr])) ~p))
with maybe better name.(default nil ?x :default)
If the value matches nil
pattern match ?x
against :default
otherwise pattern match with ?x
.@qythium by switching that and
to an or
in the substitution compiler I get
(rewrite [{}]
[{:k (seqable !x ..!n)} ...]
[{:k [!x ..!n]} ...])
;; =>
[{:k []}]
There are two failures though
FAIL in meander.epsilon-test/subst-mvr-rp*-test (epsilon_test.cljc:2023)
expected: [[1 :a] [2 :b]]
actual: [[1 :a] [2 :b] [3 nil]]
diff: + [nil nil [3 nil]]
FAIL in meander.epsilon-test/subst-mvr-rp*-test (epsilon_test.cljc:2025)
expected: [[:a 1] [:b 2]]
actual: [[:a 1] [:b 2] [nil 3]]
diff: + [nil nil [nil 3]]
from these tests
(let [!1s [1 2 3]
!2s [:a :b]]
,,,
(t/is (= [[1 :a] [2 :b]]
(r/subst [[!1s !2s] ...])))
(t/is (= [[:a 1] [:b 2]]
(r/subst [[!2s !1s] ...])))
Maybe the check should only be looking at memory variables that are top-level to the …
I vote yes