This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-15
Channels
- # beginners (15)
- # boot (4)
- # cider (1)
- # cljsrn (16)
- # clojars (1)
- # clojure (92)
- # clojure-india (3)
- # clojure-russia (27)
- # clojure-spec (9)
- # clojure-uk (5)
- # clojurescript (73)
- # cursive (28)
- # datascript (10)
- # emacs (1)
- # events (5)
- # hoplon (1)
- # instaparse (7)
- # juxt (2)
- # klipse (13)
- # lumo (17)
- # off-topic (166)
- # onyx (4)
- # protorepl (5)
- # re-frame (5)
- # reagent (13)
- # rum (26)
- # untangled (17)
- # yada (3)
@j-po why are you asking me? (curious)
Alex Miller updated it after me đ I did almost nothing of substance on that library anyway. Cosmin wrote it.
(his last update was August 2012 thoâ)
The only changes since Cosmin touched it have been purely cosmetic â updating parent pom and adding the contributing notes.
postwalk
is a strange beast⌠I think @hiredman is right that youâre hitting MapEntry
objects that satisfy vector?
and so youâre trying to convert those into arrays of hash maps.
map-entry?
exists but I think it was only added recently (1.9). What version of Clojure are you using @j-po ?
It was added in 1.8 and there were changes related to it in postwalk
I think there might actually be an open ticket on something related to this
We do have map-entry?
but even
(defn- java-y [form]
(walk/postwalk #(cond (map? %) (java.util.HashMap. %)
(map-entry? %) %
(vector? %) (into-array java.util.HashMap %)
:else %)
(walk/stringify-keys form)))
throws java.lang.IllegalArgumentException: array element type mismatch
Youâll have to add some debugging to your function â print out the types of the items it is called on. Using postwalk
and prewalk
to convert expressions is always pretty fraught in my experience.
In the vector?
case, youâll probably want to print (mapv type %)
to see what all the element types are.
(the discussion there suggests trying to use prewalk
instead of postwalk
but that may or may not help you)
I reported that based on a similar discussion here in #clojure some time ago.
yes, you can only detect a map entry in a prewalk
In postwalk
, the MapEntry
has already been rewritten as a vector, unfortunately. Thatâs what CLJ-2031 is about.
(Prewalk also won't work for our case because it seems like the Java types aren't walkable.)
Sounds like youâd be better off writing your own specialized expression walker / converter thenâŚ
@j-po with specter it's:
(defn java-convert [data]
(let [node-walker (recursive-path [] p
(cond-path
map? (continue-then-stay MAP-VALS p)
vector? (continue-then-stay ALL p)
))]
(transform node-walker
(fn [e]
(if (map? e)
(java.util.HashMap. e)
(into-array Object e)
))
data
)))
should be higher performance than using postwalk
as well
I find it's almost always better to be precise about what you're traversing, avoids the pitfalls of doing a brute force postwalk
hello
Hi, hello:joy: @douglasclive
is there something similar to clojure.spec/assert, but it runs even when s/ehceck-aseerts is false ?
The anonymous function really annoys me, but I havenât found a better solution to this âidiomâ
i personally like the (when-let [errors (s/explain-data ::spec v)] (throw (ex-info ...)))
approach
What is the story of Clojure on Android nowadays? I have been searching the net and it seems that Clojurescript + React Native side seems to be the only active one. Unfortunately that is not really ideal for many things for example for games
Can any HoneySQL advocates out here possibly comment on any advantages compared to good old korma? I implemented something with HoneySQL, but looking at korma in the back mirror, it looks, well, simpler (even if not easier, to borrow from simple v.s. easy).
For debugging, having a function that generates a query that you run, rather than a macro that generates and also runs a query, seems a bonus. Maybe I just don't know enough about korma to know where it exposes that, if it offers it.
@neurogoo here's one relevant link: https://github.com/tahmidsadik112/Replicator
Not strictly clj, but any Postgres nerds here? Iâm wondering if this is an efficient way to select a random row from a large (5M+) query result set. Iâm thinking itâs not because you have to get the resultset first. But Iâm not sure if thereâs a better way:
WITH q as (SELECT (ip), row_number() OVER (PARTITION BY country) FROM PROXIES
WHERE country = '%s' AND active = true),
c AS (SELECT COUNT (ip) FROM q),
r AS (SELECT ceiling( (count + 0) * random()) FROM c)
SELECT * from q WHERE row_number IN (SELECT ceiling FROM r)
ugh actually I donât think btrees on disk are even the right solution, I just donât wanna give up database-y things
Hi all, I'm doing some Java interop stuff that requires me to set thread authentication every time I want to run something. Pretty much the equivalent of this process: http://docs.oracle.com/cd/E28280_01/apirefs.1111/e17060/oracle/odi/core/security/SecurityManager.html
I've got the option of creating a set of functions that wrap the above, and other functionality in a do
, but is there an obvious alternative I'm missing?
Hmm... I'm not a very good postgres geek, but one thing to be aware of is that CTEs are optimization boundaries in Postgres.
I don't know if it matter much for your particular query, but I've found that eliminating them an lead to a ten-fold (or greater) increase in performance in some cases. If you are about the performance of your queries you should always at least look at CTEs with a jaundiced eye.
For instance see: http://blog.rhodiumtoad.org.uk/2009/03/08/selecting-random-rows-from-a-table/
I'm generally inclined to think that if I can push an operation onto the database, properly, it is likely to beat any simple ad-hoc solution I'm likely to come up with easily. So I think your instinct is correct.
My Luminus app compiles but when I submit a form I get âjava.lang.RuntimeException: EOF while reading string, compiling:(null:3:1)â
(defn searchresults [params] (let [form-schema {:country [st/required] :commodity1 [st/required] :commodity2 [st/required] :commodity3 [st/required] :devel_status [st/required]} [errors _] (st/validate params form-schema)] (if (nil? errors) (l/render âsearchresults.htmlâ {:results (db/sql-search {:country (Integer/parseInt (params :country)) :commodity1 (Integer/parseInt (params :commodity1)) :commodity2 (Integer/parseInt (params :commodity2)) :commodity3 (Integer/parseInt (params :commodity3)) :devel-status (Integer/parseInt (params :devel_status))})}) (l/render âerrors.htmlâ {:errors errors đ params}))))
Solved by re-running lein run
which means, err, not really solved as I donât have a clue what happened. Clojure âmagicâ??
@bradford Well, I hope that helps, but... don't take me too seriously. Without knowing your exact use-case, etc, having the opportunity to look at your actual schema and data, etc., anything I say is likely to be at best a hint, and at worst a rabbit-hole.
@tagore Yeah â I basically have a list of a few million proxies, and I need to choose one at random đ
If you use incrementing integers for ids, for instance, and the performance of this query really matters, you could just keep track of the highest id you've generated and select a random number below that.
But.. are your ids spare? Than you might have to generate random numbers until you got lucky.
That might still be a lot faster than a search within known ids. Depends on how sparse your ids are.
anyone have an opinion on whether using clojure.spec to make sure a server is up is a good idea?
@tagore Yeah, my IDs are over the IP address space sooooo sparse. But thanks for the good thinkinâ
What are middleware factories
? iâm reading about boot from the link below and the term came up. I have heard the term middleware (though im not sure it has sunk in) and factories, but i sense something more specific is being referred to.
Here it is in context:
> Boot addresses this problem by treating tasks as middleware factories
Link: http://www.flyingmachinestudios.com/programming/boot-clj/
it's a function that takes some arg(s) and returns a middleware
a middleware in this case being a function that takes a handler function and returns a new, wrapped, handler function
it can add steps before or after the initial handler is run
(defn verbose-middlware [f] (fn [& args] (println "calling f with" (pr-str args)) (let [res (apply f args) ] (println "f returned" (pr-str res)) res)
- a simple middleware
it does exactly what f does, plus a bunch of printing
a middleware factory is one level abstraction above that
the most common middlewares alter the args (by adding context or pruning or substituting some parameters), though some alter the return value, and a few rare do both
oh, and some decide conditionally whether to run the handler function at all
That makes sense. thanks @noisesmith
How do I convert the following to "garden" ? (the css library that looks like hiccup)
tbody tr:nth-child(odd) {
background-color: #ff33cc;
}
tbody tr:nth-child(even) {
background-color: #e495e4;
}
by garden, I'm referring to: https://github.com/noprompt/garden