Fork me on GitHub
#beginners
<
2019-11-26
>
penryu09:11:56

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

penryu09:11:29

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

aisamu11:11:57

Using maven 😬

andy.fingerhut15:11:18

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.

penryu17:11:42

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.

andy.fingerhut17:11:14

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

penryu09:11:13

my project uses deps.edn

penryu09:11:54

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

juan.ignacio84810:11:07

(def x 2)

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

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

juan.ignacio84810:11:25

is foo referentially transparent?

aisamu11:11:07

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

juan.ignacio84811:11:33

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

regen13:11:45

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

regen13:11:38

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

michael.e.loughlin13:11:22

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!

andy.fingerhut15:11:03

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.

andy.fingerhut15:11:09

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.

imparato.andrea16: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?

andy.fingerhut16:11:39

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?

imparato.andrea16:11:22

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

andy.fingerhut16:11:37

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

imparato.andrea16:11:54

yep, with the same field so i can extract it

imparato.andrea16:11:02

without parsing manually the string

andy.fingerhut16:11:40

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.

imparato.andrea16:11:54

oh ok, so i need to parse the string anyways

andy.fingerhut16:11:49

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.

dpsutton16:11:55

how did you end up with that string?

imparato.andrea16:11:57

i will just split it on the =

imparato.andrea17:11:17

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

dpsutton17:11:49

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

imparato.andrea17:11:05

this is the result of a query on solr

imparato.andrea17:11:13

and solr treats uuid as strings for some reason

imparato.andrea17:11:21

:exploding_head:

dpsutton17:11:22

but you have an object there

dpsutton17:11:32

that got pr-str'd it seems

imparato.andrea17:11:29

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

imparato.andrea17:11:46

it comes like this because uuids are strings

dpsutton17:11:00

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

dpsutton17:11:15

somewhere something is calling .toString on an object

dpsutton17:11:23

which is the bad bit

imparato.andrea17:11:26

i think it’s the library

imparato.andrea17:11:54

this is how you define it on the schema

dpsutton17:11:57

which library?

dpsutton17:11:15

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

imparato.andrea17:11:39

org.apache.solr/solr-solrj

imparato.andrea17:11:45

this is what we use

dpsutton17:11:36

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

assertEquals(NUM_INDEXED_DOCUMENTS, documents.getNumFound());
for(SolrDocument document : documents) {
  assertTrue(document.getFieldNames().contains("id"));
  assertTrue(document.getFieldNames().contains("name"));
}

dpsutton17:11:43

that lib returns objects not strings

imparato.andrea17:11:28

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

imparato.andrea17:11:48

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

nick.romer19:11:50

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?

andy.fingerhut19:11:23

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.

alberson21:11:35

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

hiredman21:11:03

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

hiredman21:11:03

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

hiredman21:11:01

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

alberson21:11:24

Nice, thank you

tws21:11:13

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

tws21:11:28

kinda weird tho

alberson21:11:08

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

mario.cordova.86222: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?

hiredman22:11:27

use a connection pool library

mario.cordova.86222:11:44

I believe I am using a connection pool

hiredman22:11:55

then you shouldn't need to check connections

mario.cordova.86222:11:36

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

hiredman22:11:08

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

hiredman22:11:18

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

mario.cordova.86222:11:39

checking if I have access

hiredman22:11:30

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

mario.cordova.86222:11:35

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

mario.cordova.86222: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.cordova.86222:11:55

But its so slow that the client times out

mario.cordova.86222:11:09

idk if its even slow to be honest

mario.cordova.86222:11:58

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

hiredman22:11:20

because you are overwhelming your connection pool

hiredman22:11:32

actually the database

hiredman22:11:44

most databases have connection limits

mario.cordova.86222:11:01

But even just running one takes a good bit

hiredman22:11:12

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

mario.cordova.86222:11:24

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

hiredman22:11:07

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

hiredman22:11:45

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.cordova.86222:11:15

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

mario.cordova.86222:11:21

it takes like a minute

fabien.rozar22:11:18

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?