Fork me on GitHub

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 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"]]


oh man I added it as a dependency not a plugin, let me try that


That was it, thanks Sean


@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:

(require '[ :as cp])

(#object[ 0x61c21b0a "/Users/matthew/.asdf/installs/java/openjdk-17/lib/"])


I am on openjdk17, arm (mac m1)


(System/getProperty "java.class.path")


what is the output for this ^?


Lots of jars as specified in the deps.edn


This is actually an X,Y problem. I am using to auto reload namespaces.


However, I found I have to explicitly set set-refresh-dirs


Though the docs says,

The directories to be scanned are controlled by 'set-refresh-dirs';
  defaults to all directories on the Java classpath.


I’d expect the refresh-dirs have been automatically populated.


I switch to jdk8 zuul and everything works fine.


It seems there are some issues with jdk17 (openjdk).


when you say "openjdk, ARM" that could be a bunch of different things


can you get the property "java.vendor" or "java.vm.vendor"


or "java.vendor.version"


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:


OpenJDK Java 17 is not specific enough


using that JDK, please provide the output of the properties I mentioned


I have seen that some people have cljr-magic-require-namespaces as shown here: 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 know, but I'd like to be able to just type pp/pprint


I understand. But I'd like to be able to use clj-magic-require-namespaces


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`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))

lightsaber 1
duckie 1
Muhammad Hamza Chippa19:01:12

{: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

Cora (she/her)19:01:53

(update-in {:subscribed-events [{:event_id 4525869}]} [:subscribed-events 0 :event_id] inc)
;; => {:subscribed-events [{:event_id 4525870}]}

Cora (she/her)19:01:15

you can look at the examples people have graciously provided on for more examples, too

Muhammad Hamza Chippa19:01:59

@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.

🙌 1

update-in expects a function followed by arguments. You had (conj {:event_id 15}) instead which isn't a function.

Muhammad Hamza Chippa19:01:33

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

🙌 1
Muhammad Hamza Chippa19:01:47

Got it Sir, thanks for Guiding

Muhammad Hamza Chippa20:01:13

@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?

Muhammad Hamza Chippa20:01:28

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


Do you need additional data in :subscribed-events beyond just the IDs?

Muhammad Hamza Chippa20:01:29

your suggestion will work for me this sounds too good

Muhammad Hamza Chippa20:01:31

btw which data structure #{} is ?

seancorfield20:01:17 has a lot of good information on this topic.


Another one, very useful for people new to clojure:

Muhammad Hamza Chippa21:01:47

@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
 (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
 (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.

Muhammad Hamza Chippa21:01:00

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
 (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
 (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)
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')


(and it would be the same with [] instead of nil -- you need #{} to start with or use the fnil versions above)

Muhammad Hamza Chippa21:01:21

Got it basically I did not initialize :subscribe-events with map so it is a list and disj don't work with the list ?

Muhammad Hamza Chippa21:01:06

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

Muhammad Hamza Chippa22:01:14

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)

Muhammad Hamza Chippa22:01:03

basically I am getting this type of response from the api

Muhammad Hamza Chippa22:01:31

I am using this code :add-subscribe-event is working fine where as :remove-subscribed-event is not working

 (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
 (fn-traced [{:keys [db]} [_ event_id]]
   {:db (update-in db [:user :subscribed-events] (fnil disj #{}) event_id)}))