This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-21
Channels
- # announcements (13)
- # babashka (29)
- # beginners (52)
- # calva (95)
- # cider (18)
- # clj-commons (7)
- # cljs-dev (42)
- # clojure (121)
- # clojure-australia (1)
- # clojure-dev (39)
- # clojure-europe (36)
- # clojure-france (4)
- # clojure-greece (1)
- # clojure-italy (20)
- # clojure-nl (3)
- # clojure-portugal (1)
- # clojure-uk (7)
- # clojurescript (47)
- # conjure (2)
- # cursive (9)
- # datalevin (5)
- # datascript (8)
- # datomic (68)
- # defnpodcast (2)
- # deps-new (5)
- # fulcro (18)
- # graalvm (21)
- # gratitude (9)
- # jobs (6)
- # jobs-discuss (17)
- # leiningen (3)
- # lsp (80)
- # lumo (1)
- # malli (9)
- # mount (2)
- # off-topic (16)
- # other-languages (8)
- # podcasts-discuss (19)
- # reitit (5)
- # remote-jobs (5)
- # shadow-cljs (29)
- # sql (5)
- # tools-deps (13)
- # vim (11)
- # xtdb (19)
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?
(swap! values (fn [m] (update m :data #(filterv (fn [{:keys [a]}] (not= a "test")) %))))
uh almost, edited
(swap! values assoc-in [:data] (into [] (remove #(= (:a %) "test") (:data @values))))
efficient, not sure, but there is an atomicity difference between yours and mine I think
you deference the atom twice, once in (:data @values)
and once in the swap!
operation
so, the list you removed maps from may have changed before your change was ready to be swapped in. If that makes sense
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
Could anyone recommend Programming Clojure
vs Getting Clojure
as a first clojure learning resource?
I’ve been enjoying the style of Getting Clojure
I’m coming back to Clojure after having first made an effort to learn it a few years ago though
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.
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)
Heh, I was most definitely “coming from Java” back when I first read Programming Clojure 🙂
Russ talks through some of the book here, in neat categories with great progression: • Data: https://podcasts.apple.com/us/podcast/s1-e2-data-with-russ-olsen/id1461500416?i=1000438141815 • Code: https://podcasts.apple.com/us/podcast/s1-e3-code-with-russ-olsen/id1461500416?i=1000439040140 • State: https://podcasts.apple.com/us/podcast/s1-e4-state-with-russ-olsen/id1461500416?i=1000440022102
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.
"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.
yaah wait check your dm
I think it's not a public link. this is for the intern, I am appllying for.
https://github.com/Croooook/clojure-polylith-realworld-example-app#start-it-in-your-clojure-repl see the readme file
@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. https://github.com/Croooook/clojure-polylith-realworld-example-app/blob/e242541e65f93c56055c09a0c587ade90e532eb2/deps.edn#L4-L44 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 https://clojure.org/guides/deps_and_cli
• Read this to understand what aliases are in the context of Clojure CLI tools https://practical.li/clojure/reference/clojure-cli-tools/defining-aliases.html
• Check out the deps.edn files of other projects to figure out how they are structured, e.g. https://github.com/clojure/core.async/blob/master/deps.edn or https://github.com/seancorfield/next-jdbc/blob/develop/deps.edn or https://github.com/rm-hull/nvd-clojure/blob/master/deps.edn
Thanks! to both of you sir.
Since Calva is mentioned in the task, this page could be relevant: https://calva.io/polylith/
You are super welcome to ask for Calva help in #calva. And there is also a #polylith channel.
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.
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: https://calva.io/get-started-with-clojure/
go team 🚂
(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)))
(t/run-tests)
doing once fixture
doing each fixture
{:test 1, :pass 0, :fail 1, :error 0, :type :summary}
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.