This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-11
Channels
- # announcements (1)
- # asami (10)
- # aws (36)
- # babashka (1)
- # beginners (32)
- # biff (13)
- # calva (2)
- # cider (2)
- # clj-kondo (3)
- # cljs-dev (5)
- # clojure-poland (2)
- # clojured (5)
- # clojurescript (7)
- # core-logic (13)
- # core-matrix (2)
- # core-typed (1)
- # datomic (1)
- # fulcro (19)
- # gratitude (6)
- # meander (15)
- # minecraft (4)
- # pathom (3)
- # podcasts-discuss (2)
- # reagent (19)
- # releases (1)
- # shadow-cljs (69)
- # sql (3)
- # tools-deps (22)
- # vim (1)
Why can’t I use &
for sets?
(m/rewrite #{:one :two :three}
#{:one & ?rest} ?rest)
gives
No method in multimethod 'ground?' for dispatch value: :amp
I expect it to only match if :one
exists and then bind the other values except :one
to ?rest
.
@UPD88PGNT You can use &
for sets but it is limited because it hackily use meta.
#{1 2 ^& ?rest}
This is because, for sets, the elements will end up unordered so there is obvious way to know what the pretzel should apply to.
If I can just remember this then I’ll be happy enough.
(defn step
[[left right]]
(m/rewrites [left right]
[(m/and #{:you}
(m/app #(disj % :you)
(m/app vec [!a ... ?x . !b ...]))) ?right]
[[!a ... !b ...] [?x :you & ?right]]
[?left
(m/and #{:you}
(m/app #(disj % :you)
(m/app vec [!a ... ?x . !b ...])))]
[[?x :you & ?left] [!a ... !b ...]]))
(defn step
[[left right]]
(m/rewrites [left right]
[#{:you ^& (m/app vec [!a ... ?x . !b ...])} ?right]
[[!a ... !b ...] [?x :you & ?right]]
[?left #{:you ^& (m/app vec [!a ... ?x . !b ...])}]
[[?x :you & ?left] [!a ... !b ...]]))
A solution to this problem would be to simply have a non-literal syntax (as is slowly being worked out on zeta but could be added to epsilon):
(m.set/union (m/hash-set p1 p2 p3) ?rest)
(defn step
[[left right]]
(m/rewrites [left right]
[#{:you ^& (m/seqable !a ... ?x . !b ...)} ?right]
[#{^& [!a ... !b ...]} #{?x :you ^& ?right}]
[?left #{:you ^& (m/seqable !a ... ?x . !b ...)}]
[#{?x :you ^& ?left} #{^& [!a ... !b ...]}]))
(step [#{:fox :corn :you} #{:goose}])
;; ([#{:corn} #{:you :fox :goose}] [#{:fox} #{:you :goose :corn}])
Oh right, it actually gets cleaner than that.
(defn step
[[left right]]
(m/rewrites [left right]
[#{:you ^& ?left} ?right]
[?left #{:you ^& ?right}]
[#{:you ?x ^& ?left} ?right]
[?left #{?x :you ^& ?right}]
[?left #{:you ^& ?right}]
[#{:you ^& ?left} ?right]
[?left #{:you ?x ^& ?right}]
[#{?x :you ^& ?left} ?right]))
(step [#{:you :corn :fox} #{:goose}])
;; ([#{:fox :corn} #{:you :goose}] [#{:corn} #{:you :fox :goose}] [#{:fox} #{:you :goose :corn}])