meander

Richie 2022-06-11T00:57:44.735779Z

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

Richie 2022-06-11T00:58:37.483079Z

I expect it to only match if :one exists and then bind the other values except :one to ?rest.

noprompt 2022-06-11T01:50:06.510049Z

@rgkirch You can use & for sets but it is limited because it hackily use meta.

#{1 2 ^& ?rest}

Richie 2022-06-11T01:50:26.670809Z

Oh…

noprompt 2022-06-11T01:50:30.460219Z

Yah

noprompt 2022-06-11T01:51:19.415379Z

This is because, for sets, the elements will end up unordered so there is obvious way to know what the pretzel should apply to.

Richie 2022-06-11T01:51:57.283019Z

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 ...]]))

Richie 2022-06-11T01:52:31.594389Z

It is much shorter.

Richie 2022-06-11T01:52:54.181849Z

Thanks!

noprompt 2022-06-11T01:52:55.336689Z

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)

noprompt 2022-06-11T01:53:35.815119Z

Ah, glad it worked out for you! 😅

Richie 2022-06-11T01:58:25.420339Z

(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}])

noprompt 2022-06-11T02:22:07.506629Z

🙂

Richie 2022-06-11T02:55:54.968749Z

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}])

Richie 2022-06-11T02:56:00.421039Z

Cool!