Fork me on GitHub
Ian Fernandez03:06:44

how can I get a var defined in a ns and create a keyword from this var?

Ian Fernandez03:06:17

(def a 1) #'user/a

Ian Fernandez03:06:33

(some-func a) => :user/a

Ian Fernandez03:06:44

what is this some-func? this func exists?


there's a couple tricky points to this question. (def a 1) creates a var with the value 1 when (some-func a) is evaluated, it will call some-func and pass the value of user/a and not the var itself. To get the var itself, you need to use the special form (var a) which is almost always abbreviated using the special syntax #'a You can get information about the var by examining its metadata (ie. (meta #'a)). You create a keyword from a var by doing something like:

user> (def a 42)
user> (let [m (meta #'a)
            ns (:ns m)
            nm (:name m)]
        (keyword (str (ns-name ns))
                 (str nm)))

thanks3 1

Note that if you wanted a function to do this, you would have to call it like (some-func #'a).

Ian Fernandez03:06:17

Basically this is tricky since I want to form namespaced keywords from some vars on a namespace

Ian Fernandez03:06:43

I want to select some vars defined in a ns and form keywords with it


What are you going to do with the keywords?

Ian Fernandez03:06:20

use then in another namespace to call a function

Ian Fernandez03:06:28

in *ns* => a I want to define some vars and a function

Alex Miller (Clojure team)03:06:48

why don't you just use the vars? why the keywords?


Based on your question, it sounds like there's a way to do what you're trying to do, but it also sounds like what you're trying to do might not be the best approach. More info about your use case and an example might help.

Ian Fernandez03:06:09

I think I'm going too far with abstractions and forgot the starting point hahahah

😁 1
Jon Olick03:06:40

with the following, its doing a (filter (complement #{:a}) #{:b :c :d :a :e}) from what I can tell… but how is #{:a} a function? thats a set?

(remove #{:a} #{:b :c :d :a :e})

phronmophobic03:06:18 > Sets are functions of their members, using get: >

(s :b)
> -> :b
> (s :k)
> -> nil

Martin Půda04:06:14

You can use as function any object that implements IFn ( that means sets, vectors, hash maps, keywords, symbols or anything created with fn .

Jon Olick15:06:33

so does it grab like the first element of the set and then like call get with it?

Jon Olick15:06:44

not clear how that works


(some-set x) behaves at least fairly similarly to (get some-set x) (I do not have memorized whether there are any differences)


i.e. It returns x if the value is in the set, otherwise nil

Jon Olick16:06:51

basically its like a is there anything in there thats also in this

Jon Olick16:06:03

or in this case

Jon Olick16:06:19

iterate over the second argument, excluding things in the first set

Jon Olick16:06:27

easy-peasy, thanks! 🙂


I don't see how iteration comes into it. (get some-set x) checks whether one value is in the set, or not.

Jon Olick16:06:39

in the filter command


Ah, sorry, I was forgetting your original question and focusing on the (some-set x) expression. My fault.


I have stored a chunk of collection in variable temp, How to identify the size of the variable in clojure? like 1mb or 2 mb?

Ben Sless08:06:17

Why do you care about its size? There's some hidden assumption here


@UK0810AQ2 My intention is, if the data in that variable exceeds 1MB i wanted to download the value as file format

Ben Sless09:06:58

where is the data coming from to begin with?


I am reading those data from a file, if data size is 1 MB then i will convert that to file, else I want to display the contenet in the front end

Ben Sless09:06:54

are you on Clojure or ClojureScript?


clojure from backend and clojurescript from frontend

Ben Sless09:06:21

and the check is in backend?

Ben Sless09:06:07

Why not use java.nio.file.Files.size(path)?


In my scenario cannot check the file size , Data will be filtered from logic and those data size should be validated

Ben Sless09:06:41

And do you care about the size of the objects in memory or the size of text you'll be sending to the frontend?


size of the objects in the memory

Ben Sless09:06:38

okay, so clj-memory-meter might suite your needs


it is for jdk more than 9


@U01J3DB39R6 if you are buffering it all in memory anyways, why not just load it as a byte array and then use .length on it?


its not 100% accurate, but its good enough for your heuristic


and when you return the response indicating how it should be downloaded, use a ByteArrayInputStream


tried this

user=> (.getBytes {:a "a"})
Execution error (IllegalArgumentException) at user/eval38 (REPL:1).
No matching field found: getBytes for class clojure.lang.PersistentArrayMap


you can ignore the keywords and tree walk values and sum them up? I was thinking you had just one string


Anyone has a sample of a reitit router usage in a clojurescript project?

Ferdinand Beyer11:06:23

Have you checked out the official examples in the reitit repo? There are 6 frontend example projects:

👍 1

@U031CHTGX1T thank you for pointing out that there were 6 of them. I was using just the frontend example and was a little confused. I just hopped in the frontend-prompt and it got me where I need to be.

👍 1
Jim Strieter13:06:13

Does anyone know why lein test would complain about a syntax error even though requiring the same file in repl does not?

(defn update-strikes
  (if (:last-bar-in-day state)
    ;; If this is last bar of the day, give every ticker an empty set:
    (assoc state :strikes (map-kv (fn [x] #{}) (:spot state)))
    (if (not (:first-bar-of-day state))
      ;; If this is NOT the first bar of the day, simply return state:
      ;; If this *is* first bar of day, add stuff to set:
      (loop [ticker-list (:ticker-list (:parameters state))
             state' state]
        (if (empty? ticker-list)
            (rest ticker-list)
              [:strikes (first ticker-list)]
              (let [old-set (get-in state' [:strikes (first ticker-list)])
                    new-set (clojure.set/union old-set (make-strike-set state' (first ticker-list)))] ;; <----- lein test complains error is here
I load this function at REPL and use it just fine. Only lein test complains there is an error!


would help a lot to see actual error


what is the error?


I think I know. the error probably looks similar to this:

Syntax error (ClassNotFoundException) compiling at (foo/core_test.clj:7:16).

Full report at:
Tests failed.
add clojure.set into the list of :require in namespace declaration

🙌 3
Jim Strieter14:06:57

that worked. Thank you!

Ferdinand Beyer15:06:06

“Syntax” error 🙂 (Aren’t LISPs proud for the lack of syntax?)


I would say minimalistic instead of "lack of" :)


"Calling a provisional deficit a syntax error does not make it a syntax error." - Abe Lincoln


What's the cause of error like

"<A /> is using incorrect casing..."
Can't see any issue in the generated output

Bramhesh Srivastav14:06:42

hallo group, another noob happy to be here.

👋 5
🐣 1

welcome! we're glad to have you! 🎉

Bramhesh Srivastav14:06:50

Thanks! i am working on some clojure script off youtube videos and also looking at crux db. Couldn;t set up datomic local. Have also watched many Rich Hickey talks about a dozen times each. 🙂

💜 1
Jon Olick15:06:02

how do you break out of an infinite doseq?


doseq has a :while clause


user=> (doseq [x (range) :while (< x 2)] (println x))

Jon Olick15:06:35

looking for something kind of like reduced


Use run!. It relies on reduce, therefore it supports reduced :

(run! (fn [x]
        (if (< x 10)
          (prn x)
          (reduced nil)))


If I have a data structure with a bunch of namespaced keywords, and aliases established for some of those keywords, is there a way to print out that data structure with the aliases applied to the keywords?


(def namespace->alias
  (set/map-invert (update-vals (ns-aliases *ns*) ns-name)))

(walk/postwalk (fn [form]
                 (if-let [new-ns (and (keyword? form)
                                      (some->> form namespace symbol namespace->alias))]
                   (keyword (str ":" new-ns) (name form))
               {::io/a {::set/b [::io/c ::set/d]}
                ::io/e ::set/f
                :unaliased :unaliased})


you can us ns-aliases to get the aliases and then walk the structure


Thanks @U11BV7MTK. I haven't used walk before. That's going to take some dissection. Is there not some sort of printer setting or something like that which can control this without having to manually walk the code? Not sure "printer setting" is the right term here..


no there is not


the reader expands ::alias/name. it’s just sugar and doesn’t exist as a value


I see. Is that walk namespace important to become familiar with? Should I put some time into studying it?

Jon Olick15:06:20

I'll just use loop/recur instead I guess

Jim Strieter20:06:56

What is an efficient way of using all the values in one map to update another? Supposing I start with:

{:a 0 :b 0 :c 0}
what should some-func be so that this:
(some-func {:a 0 :b 0 :c 0} {:c 42})
evaluates to this:
{:a 0 :b 0 :c 42}

Alex Miller (Clojure team)20:06:07

or (assoc {:a 0 :b 0 :c 0} :c 42) is more natural if you don't have the replacement already in a map

Alex Miller (Clojure team)20:06:34

and merge is another option (but prob slower for this)

Jim Strieter20:06:37

I had no idea that conj will do that. Thanks! 🙂

Michaël Salihi09:06:45

Me too! TIL that conj can be used instead of merge in this case. Thx @U064X3EF3!

Jon Olick21:06:53

so if I do (map {:this :that} list-of-maps-of-this-that-and-others) will it return a sub-list of maps of just :this and :that ?


(map f [x y z]) will return a lazy list of ( (f x) (f y) (f z) ). a map of {:this :that} when invoked as a function will perform a lookup on the argument. Hard to parse what “list-of-maps-of-this-that-and-others” is but your question can be answered by thinking about how ({:this :that} <arg>) behaves

Jon Olick21:06:28

yeah thats the fundamental question here, what does that format mean?

Jon Olick21:06:45

map would have to implement ifn, which would do what exactly?


terminology gets a big ambiguous here for “map”. i’ll use the term hashmaps to disambiguate. hashmaps do implement IFn and it behaves as a lookup


({:a 1} :a) -> 1

Jon Olick21:06:37

What if it was a hash map and a hash map

Jon Olick21:06:46

I already get the keyword thing

Jon Olick21:06:03

Does it like intersect the structures?


no. it just behaves as a lookup


there’s nothing special about keyswords. it is just looking for the argument in the hashmap

Jon Olick21:06:36

oh so it would like look for a key that exactly matches the other hash map's key

Jon Olick21:06:40

as if it was a key

Jon Olick21:06:02

which is different than set, where set would like intersect them or something

Jon Olick21:06:13

(so confusing the different ways to do everything)

Jon Olick21:06:28

sometimes it feels like it lacks consistency for the sake of succientness


what consistency is lacking?

Jon Olick21:06:17

well (set-a set-b) does an intersection of the sets

Jon Olick21:06:22

but doing the same with a hash map does not


it does not do that


(#{:a} #{:b}) is a membership check and returns nil


because the set #{:b} is not a member of the set containing :a

Jon Olick21:06:05

membership, intersection, tomato tomaato

Jon Olick21:06:42

(is (= (remove #{:a} #{:b :c :d :a :e}) (:e :c :b :d)))

Jon Olick21:06:12

maybe not the best example

Jon Olick21:06:17

but syntax is confusing


understandable. break things down and work in a repl. read docstrings and ask questions here 🙂


do you want to work through the logic of (remove #{:a} coll)?

Jon Olick21:06:56

maybe a bit later 🙂 busy atm with some work stuff


(so confusing the different ways to do everything) I feel your pain, @U036UA9LZSQ, and coming from a Common Lisp background I agree. CL also has lots of ways of doing things, but not the odd syntax tricks where, eg, data structures become functions. Hang in there, follow Dan's advice, and you will soon get past this surface issue and then enjoy the succinctness.


Good day, How can I uninstall a dep that has been installed with CLI tools? e.g uninstall rum

{:paths ["src/main/clojure"]
 :deps {rum/rum {:mvn/version "0.12.9"}}}


{:paths ["src/main/clojure"]} just remove it

Alex Miller (Clojure team)22:06:47

That's not the path to it

Alex Miller (Clojure team)22:06:05

Usually it will be in -/.m2/repository/rum/rum - if you want you can delete that directory, but note that any cached classpaths may refer to it (if you encounter an issue with this, use clj -Sforce … to force a cached classpath to recompute


oh thank you alex. I had forgotten about installing dev builds. sorry @U01HBARPCFL i missed a subtlety of your question


No problem at all @U11BV7MTK. I didn't know that :paths was directly related to deps. That path was copied from a CLI tools tutorial unrelated to rum. Thanks @U064X3EF3 I'll give that a go.


paths are not related to deps. My thinking was that you had started a project and had your sources at src/main/clojure and wanted a dependency on rum so you added that. And if that’s the case you can just remove the declared dependency on rum by dropping it from your :deps map.


Got it, thanks. I have managed to remove rum following @U064X3EF3 instructions without issue

Alex Miller (Clojure team)23:06:54

Just so you know, most people typically do not manually remove libs from their maven local repo, they just let them accumulate

Alex Miller (Clojure team)23:06:40

Clojure jars are zip files of Clojure source so are typically quite small