This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-05
Channels
- # aleph (1)
- # announcements (18)
- # babashka (145)
- # beginners (70)
- # calva (34)
- # cider (3)
- # clj-kondo (98)
- # cljdoc (5)
- # cljs-dev (13)
- # clojure (134)
- # clojure-europe (57)
- # clojure-nl (4)
- # clojure-uk (4)
- # clojurescript (40)
- # code-reviews (3)
- # conjure (1)
- # core-async (5)
- # data-science (3)
- # datomic (8)
- # fulcro (9)
- # google-cloud (2)
- # inf-clojure (9)
- # jobs (1)
- # lsp (9)
- # malli (25)
- # polylith (4)
- # reitit (4)
- # releases (2)
- # remote-jobs (3)
- # rewrite-clj (8)
- # shadow-cljs (34)
- # tools-build (1)
- # tools-deps (67)
Hi sort of a pedestrian question RE leiningen and the environ lib: I am trying to provide environment specific variables through profiles in my lein project. I have a profiles.clj
file next to the project.clj
file with something like the following:
{:dev {:env {:test "ing"}}}
I read that the dev profile in leiningen is active by default, so my assumption is that this :test
key should be available after lein repl
; however I do not see this key in my environ
env
map (`(require '[environ.core :refer [env]])`) after https://github.com/weavejester/environ#usage. I did not do any composite profiles as are shown further in that example, in fact my project.clj has no profiles defined. Am I missing an additional step in my project.clj that prevents me from seeing (env :test)
return non-nil?I do not know the answer, but wanted to mention that there is also a #leiningen channel that may be a more target-rich environment for Leiningen experts than the #beginners channel.
@U01188CHUFL Did you add this to your project.clj
file?
:plugins [[lein-environ "1.2.0"]]
@U01188CHUFL I don't use Leiningen or environ
so it was just a lucky guess based on the environ
readme 🙂
Hi. I am seeing an empty list of classpath:
clj꞉app.main꞉>Â
(require '[clojure.java.classpath :as cp])
(cp/classpath)
(#object[java.io.File 0x61c21b0a "/Users/matthew/.asdf/installs/java/openjdk-17/lib/src.zip"])
This is actually an X,Y problem. I am using clojure.tools.namespace.repl/refresh to auto reload namespaces.
Though the docs says,
The directories to be scanned are controlled by 'set-refresh-dirs';
defaults to all directories on the Java classpath.
Two java versions used: 1. (Work): Zuul Java 8, compiled as arm package 2. (Does not work): OpenJdk java 17, compiled as x64 pacakge
But the docs officially claims only 8 and 11 are supported, I shall not go beyond that boundary: https://clojure.org/guides/getting_started#_dependencies
I have seen that some people have cljr-magic-require-namespaces
as shown here: https://github.com/clojure-emacs/clj-refactor.el/blob/9e1f92033449a4abc6218ce31670d89e3e6a4dc5/clj-refactor.el#L67-L91
I have cljr installed but I don't see this function. Does anyone have any idea?
I want to be able to add namespaces for experimenting without having to add them to my requires
I thinkj that's a terrible attitude to have. "oh it doesn't work, no use in trying any further, you'll just have to accept that it doesn't work
I've been doing the clojure koans and i'm on the lazy sequences part now and having a bit of trouble trying to understand why this is true:
"Iteration provides an infinite lazy sequence"
(= '(1 2 4 8 16 32 64 128) (take 8 (iterate (fn [x] (* x 2)) 1)))
Looking at the https://clojuredocs.org/clojure.core/iterate`iterate`, does the return value from each iterate get used as x
in each subsequent iteration?nevermind i guess my question was kind of dumb. I just read the description of the function for the nteenth time and realize that's exactly what this means: Returns a lazy sequence of x, (f x), (f (f x))


{:subscribed-events [{:event_id 4525869}]
I have this type of data structure how can I update another map {:event_id 15} in the data structure using update-in
(update-in {:subscribed-events [{:event_id 4525869}]} [:subscribed-events 0 :event_id] inc)
;; => {:subscribed-events [{:event_id 4525870}]}
you can look at the examples people have graciously provided on https://clojuredocs.org/clojure.core/update-in for more examples, too
@corasaurus-hex I look at that I wanted to add another map something like this {:subscribed-events [{:event_id 4525869}{:event_id 14}]}
I was trying something like this but it is not working
(update-in {:subscribed-events [{:event_id 4525869}]} [:subscribed-events] (conj {:event_id 15}))
(update-in {:subscribed-events [{:event_id 4525869}]} [:subscribed-events] conj {:event_id 15})
Remove those parens.update-in
expects a function followed by arguments. You had (conj {:event_id 15})
instead which isn't a function.
Thanks @seancorfield that solved the problem
Well, I mean it sort of behaves as a function but isn't what you want:
dev=> (conj {:event_id 15})
{:event_id 15}
so then that hash map is treated as a function and it is "called" on [{:event_id 452869}]
so it's going to return nil
:
dev=> ({:event_id 15} [{:event_id 452869}])
nil
Got it Sir, thanks for Guiding
@seancorfield to remove the map from the data structure dissoc is not working for it ?
(update-in {:subscribed-events [{:event_id 4525869}{:event_id 15]} [:subscribed-events] conj {:event_id 15})
@mhamzachippa Can you explain what code you tried, what result you got, and what result you are expecting/trying to get?
I have map like this {:subscribed-events [{:event_id 4525869} {:event_id 15}]}
and I want to remove {:event_id 15} from it for this I am using this code
(update-in {:subscribed-events [{:event_id 4525869}{:event_id 15}]} [:subscribed-events] dissoc {:event_id 15})
The value of :subscribed-events
is a vector. dissoc
only works on maps.
If you find yourself wanting to add and remove arbitrary items from a vector, perhaps you want a different data structure?
Given what you've shown so far, it seems like the important aspect of :subscribed-events
is just the event ID itself -- if you used a set of IDs for :subscribed-events
, this gets easier:
dev=> (update {:subscribed-events #{}} :subscribed-events conj 4525869)
{:subscribed-events #{4525869}}
dev=> (update *1 :subscribed-events conj 15)
{:subscribed-events #{15 4525869}}
dev=> (update *1 :subscribed-events conj 1234)
{:subscribed-events #{1234 15 4525869}}
dev=> (update *1 :subscribed-events disj 15)
{:subscribed-events #{1234 4525869}}
dev=>
Do you need additional data in :subscribed-events
beyond just the IDs?
your suggestion will work for me this sounds too good
Thank you so Much
btw which data structure #{}
is ?
A set.
https://clojure.org/reference/data_structures has a lot of good information on this topic.
Another one, very useful for people new to clojure: https://clojure.org/guides/weird_characters
@seancorfield I am basically using your approach to manipulate database of re-frame I have these events in the database, adding the event is working fine whereas deleting is not working can you detect the error in that
; re-frame event to add subscribed events in the database
(re-frame/reg-event-fx
:add-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] conj event_id)}
)
)
; re-frame event to remove subscribed events from the database
(re-frame/reg-event-fx
:remove-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] disj event_id)}
)
)
Did you make sure to initialize the :subscribed-events
value in the db
to #{}
?
Otherwise it'll be nil
and conj
will turn that into a list and disj
will not work.
you could use (fnil conj #{})
instead of just conj
and (fnil disj #{})
instead of just disj
to have that happen automatically
fnil
wraps a function to provide a default value to use in place of a nil
argument.
I can add event-id successfully but deleting it is not working at all
So your event handlers would look like:
; re-frame event to add subscribed events in the database
(re-frame/reg-event-fx
:add-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] (fnil conj #{}) event_id)}))
; re-frame event to remove subscribed events from the database
(re-frame/reg-event-fx
:remove-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] (fnil disj #{}) event_id)}))
As I said, if you don't start with a set, you'll get a sequence from conj
and then you cannot use disj
on it.
dev=> (conj nil 13)
(13)
dev=> (conj *1 42)
(42 13)
dev=> (disj *1 13)
Execution error (ClassCastException) at dev/eval100264 (dev.clj:1).
class clojure.lang.PersistentList cannot be cast to class clojure.lang.IPersistentSet (clojure.lang.PersistentList and clojure.lang.IPersistentSet are in unnamed module of loader 'app')
dev=>
(and it would be the same with []
instead of nil
-- you need #{}
to start with or use the fnil
versions above)
Got it basically I did not initialize :subscribe-events with map so it is a list and disj don't work with the list ?
(fnil disj #{}) is not working as well
Show your code -- because it works for me in the REPL:
dev=> (update nil :subscribed-events (fnil conj #{}) 13)
{:subscribed-events #{13}}
dev=> (update *1 :subscribed-events (fnil conj #{}) 42)
{:subscribed-events #{13 42}}
dev=> (update *1 :subscribed-events (fnil conj #{}) 100)
{:subscribed-events #{13 100 42}}
dev=> (update *1 :subscribed-events (fnil disj #{}) 42)
{:subscribed-events #{13 100}}
dev=> (update *1 :subscribed-events (fnil disj #{}) 13)
{:subscribed-events #{100}}
dev=>
there is one problem I am getting subscribed-events it from the api, and it is vector probably, so can you recommend me how can I do this with vector or map because I guess I am not getting map from the api although I converted vector into the set using (into #{} subscribed-events)
basically I am getting this type of response from the api
I am using this code :add-subscribe-event is working fine where as :remove-subscribed-event is not working
(re-frame/reg-event-fx
:add-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] (fnil conj #{}) event_id)}))
; re-frame event to remove subscribed events from the database
(re-frame/reg-event-fx
:remove-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] (fnil disj #{}) event_id)}))