This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-10
Channels
- # asami (41)
- # babashka (24)
- # beginners (48)
- # calva (41)
- # cider (10)
- # clj-commons (20)
- # clj-kondo (2)
- # cljdoc (8)
- # clojure (131)
- # clojure-australia (4)
- # clojure-europe (17)
- # clojure-hungary (2)
- # clojure-india (2)
- # clojure-nl (3)
- # clojure-uk (1)
- # clojurescript (12)
- # community-development (6)
- # core-logic (4)
- # cursive (11)
- # datomic (22)
- # emacs (25)
- # events (1)
- # exercism (2)
- # fulcro (30)
- # helix (5)
- # honeysql (6)
- # hugsql (3)
- # integrant (12)
- # introduce-yourself (4)
- # lsp (5)
- # malli (5)
- # nextjournal (31)
- # off-topic (4)
- # pedestal (3)
- # portal (51)
- # reitit (33)
- # remote-jobs (1)
- # shadow-cljs (12)
- # sql (10)
- # vim (7)
- # xtdb (37)
I’m trying to compare elements inside an lvar which is a hashmap (in this case, having a unique value for the :a
key). I’ve managed to do it with project
but I’ve read this is to be avoided. Is there a better way to do this? Any advice on style? m
will have over 100 entries eventually, with more complex comparison between adjacent vars
.
(def m [{:a 1 :b "foo"}
{:a 1 :b "bar"}
{:a 3 :b "baz"}])
(let [vars (repeatedly 2 lvar)]
(run* [q]
(everyg #(membero % m) vars)
(project [vars] (distincto (mapv :a vars)))
(== q vars)))
https://github.com/clojure/core.logic/blob/master/src/main/clojure/clojure/core/logic.clj#L2587 can be use to extract keys from a map, dunno the performance
(run* [q]
(fresh [ma a ma' a']
(membero ma m)
(membero ma' m)
(featurec ma {:a a})
(featurec ma' {:a a'})
(distincto [a a'])
(== [a a'] q)))