Fork me on GitHub

I have an atom with values as `(def values (atom {:data [{:a "test"} {:a "new"}]}))` I want to remove map from `:data` where `:a = "test"`


@UDF11HLKC’s answer looks right, but there are multiple problems hidden in your question. I'm seeing this a lot in most beginners (I do it quite often). As a suggestion for the future: Break hard problems down! You want to remove a map from a vector of maps that are a value in a map and that map also happens to be an atom. Broken down into smaller problems, that's more or less: 1. Given a map like {:a "test"} or {:a "new"}, can you tell whether it's a map that you want to keep or not? 2. Given a vector of maps like the above, how can you keep just the ones you want? 3. What if that vector is the value of a map key? 4. How do you store the result of such an operation in an atom?

Lennart Buit12:10:28

(swap! values (fn [m] (update m :data #(filterv (fn [{:keys [a]}] (not= a "test")) %))))

Lennart Buit12:10:08

uh almost, edited


Thanks, I tried


(swap! values assoc-in [:data] (into [] (remove #(= (:a %) "test") (:data @values))))


I am not sure which one is efficient to use ?

Lennart Buit12:10:18

efficient, not sure, but there is an atomicity difference between yours and mine I think

Lennart Buit12:10:50

you deference the atom twice, once in (:data @values) and once in the swap! operation

Lennart Buit12:10:41

so, the list you removed maps from may have changed before your change was ready to be swapped in. If that makes sense


It make sense.


I was thinking If we have about 100000 maps in it. So which will be faster

Lennart Buit12:10:01

I haven’t measured, but I’d assume yours is faster because its not as thread safe as mine. In my version, if the swap fails, it needs to filter the entire list again. In yours, it doesn’t, but it will swap in a stale filtered list


Okay, Thanks


Could anyone recommend Programming Clojure vs Getting Clojure as a first clojure learning resource?

⚔️ 1
Colin P. Hill14:10:49

I’ve been enjoying the style of Getting Clojure

Colin P. Hill14:10:22

I’m coming back to Clojure after having first made an effort to learn it a few years ago though

Alex Miller (Clojure team)14:10:16

as a co-author of Programming Clojure, I love Russ's writing :)


I’ve read both. I liked Getting Clojure for a first and then Programming Clojure as a follow up.


I learned Clojure from Programming Clojure (the first edition - it was a while ago) and I really liked it. I more recently read the third edition and it was still good.

Alex Miller (Clojure team)14:10:33

PC has a lot more "coming from Java" feel whereas I think Russ's is much more "coming from Ruby" feel (all of the above authors are polyglots of course, but that's my sensibility)

👍 3

Heh, I was most definitely “coming from Java” back when I first read Programming Clojure 🙂


Thank you all. Couldn’t decide between the comments so I just got both

😺 1
😎 2

what do someone mean by "Just ensure to include :dev and :test aliases in your project"?


i can think of two contexts. Good discipline to have two aliases in your project dev and test such that new people can run tests easily by just clj -A:test and can get a dev environment up easily by just clj -A:dev.


the other context is if they were telling you to start a clojure process with those aliases. clj -A:dev:test as opposed to clj


sorry I didn't get you, what do they want me to do ? add something in the code to "add these aliases" or are they asking me to run the commands you have given in the terminal anything like that.


yess the 2nd context seems to be the condition here as they are asking me to setup a clojure project running in my local machine.


i'm not sure. that's why i listed both contexts that sound plausible to me


"Setup a Clojure development environment: You will need Calva for VS Code, and sample project. The sample project uses clojure and polylith. Your goal is just get it running in your local system. "


this is the goal I have right now.


do you have a link?


yaah wait check your dm


just post it here if its a public link to a tutorial


I think it's not a public link. this is for the intern, I am appllying for.


@U02JX4YBPCH The link is public and it refers to the second context @U11BV7MTK mentioned before: > the other context is if they were telling you to start a clojure process with those aliases. `clj -A:dev:test` as opposed to `clj` The polylith project is arguably quite complicated for a beginner but in a nutshell :dev and :test are aliases in its deps.edn file. and the test alias is right below that.. As you can see they're used to define stuff like a custom classpath and dependencies. These might ease your way: • Skim the Clojure CLI tools guide • Read this to understand what aliases are in the context of Clojure CLI tools • Check out the deps.edn files of other projects to figure out how they are structured, e.g. or or

🙌 1

Thanks! to both of you sir.


Since Calva is mentioned in the task, this page could be relevant:

🙌 1

It even uses the Real World Example as the example.

🙌 1

You are super welcome to ask for Calva help in #calva. And there is also a #polylith channel.

🙌 1

I am completely new to this topic but I really want to learn it. And it's going somewhat confusing tbh.


It is a lot to take in at the same time, and we who have been in here for a while tend to forget how it was when we were completely new to it. Please bear with us, we really want to help. While you are new and experiencing the quirks, please consider sharing your experience in #improve-getting-started.

🙌 1

I think it is quite heavy to bring in Polylith into the mix right off the bat. You can prepare yourself a bit before you open that box. I have tried to pave a beginner’s path here:

🙌 1

Hello Is it possible to define both, :once and :each fixtures on the same namespace?


(ns test-ns
    (:require [clojure.test :as t]))
(t/use-fixtures :once (fn [f] (println "doing once fixture") (f)))
(t/use-fixtures :each (fn [f] (println "doing each fixture") (f)))
(t/deftest foo (t/is (= 1 2)))

doing once fixture
doing each fixture
{:test 1, :pass 0, :fail 1, :error 0, :type :summary}


lol, easy! Thnks 😄


no worries. i was reading (doc clojure.test) and it didn't say anything to the contrary and seemed to indicate it would work


Yes, this allows you to have both "around each test" and "around the whole ns" for testing. I think in most cases folks tend to just have one or the other. What I often find is missing is "around the entire test suite" (a feature that I requested for Polylith, and that was added recently). We have a wrapper for running tests at work that provides this "whole suite" fixture as well.

👍 1