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.
@rgkirch You can use & for sets but it is limited because it hackily use meta.
#{1 2 ^& ?rest}
Oh…
Yah
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 ...]]))
It is much shorter.
Thanks!
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)
Ah, glad it worked out for you! 😅
(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}])
Cool!