Fork me on GitHub

Eek. I cleaned out my ~/.m2/ cache to rule out bad caching as a cause of build failure, and now I'm getting Error: Could not find or load main class clojure.main


Is there a way to restock the cache without using lein?


Using maven 😬

😂 4

deps.edn clj / clojure commands create cached classpaths in your /.cpcache directory that often contain full path names to JAR files in your /.m2 directory. If you delete /.m2, you probably want to delete /.cpcache, too.


I don't seem to have a ~/.cpcache directory. I do have a .cpcache directory in my deps-based app directories, but clj/clojure worked outside of them before. Maybe they're looking in a different cache. I'll poke around.

☝️ 4

That one, then. I am probably off on mental model of where all .cpcache directories are created.


my project uses deps.edn


confirmed: I can go to any lein project declaring org.clojure/clojure, and run lein deps, and magically any other clj or clojure command will work


(def x 2)

(defn foo [n]
  (+ n x))

(defn bar [n]
  (+ n 2))
which one is preferred fooor bar?


is foo referentially transparent?


Here's what the REPL says:

(def x 2)
(defn foo [n]
  (+ n x))

(foo 2)
;; => 4

(def x 4)
(foo 2)
;; => 6
Perhaps direct linking would change that


You can use that property of defing a symbol to debug at the repl:


yes, the repl also told me that! So bar is the preferred way? I'm very used to extracting that 2 to a constant in Java


I think it's important to extract any magic numbers. If you're really afraid that someone might redefine the var, (which is not idiomatic) do (def ^:const x 3) and the number will be inlined in (defn foo ...)


again, that would make things less flexible when doing repl-driven development


my thought process would be "does x need a name here?" If I've written (defn halve [n] ...) and x is 2, probably not. If it's a scientific constant, probably def a var!


I believe most people would say that foo is not referentially transparent, because its return value depends upon x, which is not a parameter of foo. But then one could also ask whether a function a that calls b can ever be referentially transparent, because it depends upon the value of b.

parens 4

The term referential transparency has multiple definitions, of varying levels of mathematical precision, and I don't know all of them well enough to say according to which definitions foo is referentially transparent, and which others it might not be considered so.

Andrea Imparato16:11:47

newbie question, if i have a string “object:field=1234”, is there a way with reflection to get an object out of it?


Literally that exact string you showed? Do you want to create a new object of a particular class, or somehow refer to an already-existing object? If so, which one?

Andrea Imparato16:11:22

to be precise i have "org.apache.solr.common.SolrInputField:uuid=a63c2ecb-733c-47c6-8464-a9a9a1a8c653"


And you want to construct a new object of that class?

Andrea Imparato16:11:54

yep, with the same field so i can extract it

Andrea Imparato16:11:02

without parsing manually the string


without parsing the string, I do not know of a library function that does that. Such a thing might very well exist, and I haven't heard of it, though.

Andrea Imparato16:11:54

oh ok, so i need to parse the string anyways


I would bet different people have made up different syntaxes for representing objects as strings like that, and likely there are multiple string-incompatible functions to do things like that in different Java libraries.


how did you end up with that string?

Andrea Imparato16:11:57

i will just split it on the =

Andrea Imparato17:11:17

that is the only class and the only field i have, i don’t have to make it generic


is there a chance you can have the object? before serialization?

Andrea Imparato17:11:05

this is the result of a query on solr

Andrea Imparato17:11:13

and solr treats uuid as strings for some reason


but you have an object there


that got pr-str'd it seems

Andrea Imparato17:11:29

this is the result from the query, i can’t do much with it

Andrea Imparato17:11:46

it comes like this because uuids are strings


that's not a string of a uuid, that's a string of a java class


somewhere something is calling .toString on an object


which is the bad bit

Andrea Imparato17:11:26

i think it’s the library

Andrea Imparato17:11:54

this is how you define it on the schema


which library?


that's fine. treating the uuid as a string isn't yourproblem

Andrea Imparato17:11:39


Andrea Imparato17:11:45

this is what we use


final QueryResponse response = client.query("techproducts", queryParams);
final SolrDocumentList documents = response.getResults();

assertEquals(NUM_INDEXED_DOCUMENTS, documents.getNumFound());
for(SolrDocument document : documents) {


that lib returns objects not strings

Andrea Imparato17:11:28

i think it’s the client we use the real problem

Andrea Imparato17:11:48

i haven’t written it so i have to investigate more


Hi all, beginner here. In intellij cursive I ran-debug my code and exited with an error. Can I recover the REPL or do I need to restart it?


I do not know the answer, since I do not use Cursive, but I wanted to point out that there is a #cursive channel that may be more helpful for such questions.


Hello! I have a list of data which I need to filter. The gotcha is that the list is ordered and the data I may be interested is often in the end of it. I read the documentation of reverse and it says it is not lazy, so I'm guessing it'll traverse all the data to reverse it. Since this given list can be very large and I want a performance gain I was hoping to traverse this list in reverse, starting from the last to first. What is an elegant way to do this without traversing the whole list (like an lazyness but from the end)? Am I worried about an tiny performance improvement (eg. reverse traverse the data but since there is no operation other than traversing it will be very quick)?


you can't do that with clojure's lists or seqs, which look like singly linked lists


but most of the ways you get a large dataset as a seq involve reading the data from some external place (a database, a file, etc) so just create the list in the reverse order from the source


but in general, if you have to do anything to a list other then operate on the head (any kind of random access, or sorting, or whatever) you might want to look at alternative datastructures


Nice, thank you


if it’s in a vector, you could loop with peek, pop.


kinda weird tho


I think I'll be changing to a vector so I can use rseq @tws

Mario C.22:11:21

I am trying to check connection by mapping through a collection of connections and doing (query connection (str "SELECT TOP 1 1 AS access FROM" table) {:timeout 5}) but this is taking a long time. What is the better way to accomplish this?


use a connection pool library

Mario C.22:11:44

I believe I am using a connection pool


then you shouldn't need to check connections

Mario C.22:11:36

hmm how would I know whether I can query certain tables?


ah, I misunderstood, I thought you were checking to see if a connection is still open


are you checking to see if a table exists, or checking to see if you have permissions to access the table?

Mario C.22:11:39

checking if I have access


most databases surface permission information as a set of tables in the database, but the way that is done is database specific

Mario C.22:11:35

The end goal is to build a table showing what tables I have access to

Mario C.22:11:36

I have this ugly piece of code

(into {}
      (pmap deref
            (mapv (fn [[source meta]]
                    (let [server-type (keyword (:server-type meta))
                          meta (assoc meta :source source :server-type server-type)]
                      (future (datasource-access meta)))) wb-lookups)))
Where datasource-access ultimately makes the function call I mentioned earlier

Mario C.22:11:55

But its so slow that the client times out

Mario C.22:11:09

idk if its even slow to be honest

Mario C.22:11:58

Ultimately it returns Connections could not be acquired from the underlying database!


because you are overwhelming your connection pool


actually the database


most databases have connection limits

Mario C.22:11:01

But even just running one takes a good bit


so whatever database you are querying doesn't like you opening that many connections in parallel

Mario C.22:11:24

Should I expect a single check to be quick or is it normal for it to take a while?


it is going to depend on a lot of factors, like how loaded the database is, what is in memory on the db server. I wouldn't expect that to be super slow, but I can see how it could be, and might add up reeking havoc on the db servers block cache


I would suggest looking at the documentation for your particular sql database to see how it reflects access information as tables, and query those tables instead

Mario C.22:11:15

Got it! Ill look into just thought I was doing something wrong since it seems odd it would take that long

Mario C.22:11:21

it takes like a minute


Hello, I'm working on a textarea component generated by reagent. This component appears after a double click and I'm struggling to understand how to put the cursor of this textarea at the end of it. Do you know how I can set the position of the cursor in this texte area please?