This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-26
Channels
- # announcements (2)
- # aws (4)
- # babashka (5)
- # beginners (91)
- # calva (4)
- # cider (17)
- # clara (13)
- # clj-kondo (14)
- # cljsrn (11)
- # clojure (159)
- # clojure-europe (2)
- # clojure-nl (14)
- # clojure-norway (2)
- # clojure-taiwan (2)
- # clojure-uk (32)
- # clojurescript (101)
- # clojutre (4)
- # cursive (13)
- # data-science (1)
- # datomic (46)
- # emacs (68)
- # figwheel-main (5)
- # fulcro (48)
- # graalvm (7)
- # graphql (6)
- # instaparse (5)
- # joker (4)
- # lambdaisland (1)
- # leiningen (2)
- # malli (9)
- # off-topic (41)
- # pedestal (15)
- # re-frame (47)
- # reagent (7)
- # reitit (14)
- # shadow-cljs (180)
- # spacemacs (58)
- # specter (1)
- # tools-deps (13)
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
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.
That one, then. I am probably off on mental model of where all .cpcache directories are created.
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 foo
or bar
?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 thatYou can use that property of def
ing a symbol to debug at the repl: http://blog.cognitect.com/blog/2017/6/5/repl-debugging-no-stacktrace-required
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 ...)
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](https://emoji.slack-edge.com/T03RZGPFR/parens/76eec9b1397fa441.png)
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.
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?
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?
yep, with the same field so i can extract it
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.
oh ok, so i need to parse the string anyways
okidoki
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.
i will just split it on the =
that is the only class and the only field i have, i don’t have to make it generic
this is the result of a query on solr
and solr treats uuid as strings for some reason
this is the result from the query, i can’t do much with it
it comes like this because uuids are strings
i think it’s the library
itself
this is how you define it on the schema
org.apache.solr/solr-solrj
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) {
assertTrue(document.getFieldNames().contains("id"));
assertTrue(document.getFieldNames().contains("name"));
}
i think it’s the client we use the real problem
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)?
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
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?
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?
most databases surface permission information as a set of tables in the database, but the way that is done is database specific
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 earlierUltimately it returns Connections could not be acquired from the underlying database!
so whatever database you are querying doesn't like you opening that many connections in parallel
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