This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-12
Channels
- # announcements (1)
- # aws (1)
- # beginners (182)
- # boot (33)
- # calva (87)
- # cider (3)
- # clj-kondo (2)
- # clojure (108)
- # clojure-dev (73)
- # clojure-europe (2)
- # clojure-italy (27)
- # clojure-nl (22)
- # clojure-norway (1)
- # clojure-spec (1)
- # clojure-uk (122)
- # clojurescript (78)
- # cursive (5)
- # datomic (17)
- # duct (2)
- # emacs (25)
- # events (3)
- # figwheel (1)
- # figwheel-main (1)
- # fulcro (88)
- # kaocha (6)
- # leiningen (2)
- # luminus (1)
- # lumo (4)
- # nrepl (4)
- # off-topic (37)
- # onyx (1)
- # re-frame (35)
- # reagent (1)
- # reitit (4)
- # shadow-cljs (8)
- # spacemacs (22)
- # specter (2)
- # sql (19)
- # tools-deps (12)
- # vim (11)
(first (rest (reverse coll)))
maybe?
and (first (rest (rseq coll)))
for a vector I thinkI don't know about unidiomatic but I think I'd struggle to understand what was going on of I came across something like that
If you're doing request-reply over channels, putting a reply-to channel along with the request is a reasonable way to do it I think.
@borkdude There's take-last
What stung me is that the one without the comparator, uses compare
which returns -1, 0, 1 (as one would expect) as a comparator, whereas the arity with a user-supplied comparator expects a comparator which returns a boolean value.
Hmm, reading through the implementation, this seems even stranger, that indicates that I’m wrong 😞
user=> (sort - [23413461236412630 10000000000000000 1 0 -1])
(-1 0 1 23413461236412630 10000000000000000)
user=>
I don’t understand the (sort -)
, that’s not proper comparator. Do you want (sort >)
perhaps?
I guess I was thinking in terms of the result of running a comparator on two things, and not on a thing that implemented Comparator
in java.
I think that’s the standard way of doing sorting chars in C. Just subtract the chars from each other and you’re good.
What’s funny is that -
seems to work as a comparator for numbers that are integers, but not for longs…
pretty much, Java already comes with that, Clojure builds on top. (sort #(compare %2 %1) [\a \b \c])
that’s likely integer truncation in action, you can see with (map (memfn intValue) [23413461236412630 10000000000000000 1 0 -1])
(let [a (to-array coll)]
(. java.util.Arrays (sort a comp))
(with-meta (seq a) (meta coll)))
https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#sort(T[],%20java.util.Comparator)
public abstract class AFunction extends AFn implements IObj, Comparator, Fn, Serializable
public int compare(Object o1, Object o2){
Object o = invoke(o1, o2);
if(o instanceof Boolean)
{
if(RT.booleanCast(o))
return -1;
return RT.booleanCast(invoke(o2,o1))? 1 : 0;
}
Number n = (Number) o;
return n.intValue();
}
which probably means that sorting by a function which can return numbers which are bigger than Integers
may or may not work. I guess.
https://github.com/shriphani/clj-lmdb https://github.com/hiteshjasani/clj-lmdbj I found these
anyone have any good recommendations for a library to help doing benchmarks of external binaries?
(I don't want to benchmark things that are written in clojure/java, so basically will be using java.shell
to run the programs but like to use clojure for setup/timing/teardown)
@victorbjelkholm429 you mean record the time of external processes?
https://github.com/clj-commons/conch is convenient for scripting
@borkdude was looking for a framework-like tool to help me structure the tests themselves, but thinking about it, wouldn't be hard to do myself. Conch looks very helpful for other things, so thanks for sharing that
For those interested in writing fast scripts in Clojure this might be interesting https://github.com/jeroenvandijk/clojure-scripting
Hey all, learn-awesome is an open-source, community effort towards collecting links to awesome learning resources categorized by topics, formats, & difficulty. The idea is to build humanity's universal skills graph. The page about Clojure could use some work though. Would appreciate people here sending pull requests 🙂 https://github.com/learn-awesome/learn-awesome/blob/master/programming-languages/clojure.md
Anyone tried to use https://www.testcontainers.org/ for their integration tests but for Clojure?
I only found a java library (which we can use i guess)
not sure if this would be better in beginners, but it looks like my repl in cider is actively running some computation and blocking others. is there any way to tell what’s going on, or do i need to profile the jvm activity?
you can get all the stacktraces in a vm without a profiler
if you mean "I sent something to nrepl and it is still running, and I can send anything else to nrepl until it is done, what do I do?"
with jstack, or even sending the process a signal, you can get the stack traces, and it should be pretty straightforward to see which one would be blocking io for the repl thread
a lot of it is going to highly specific to the nrepl client, and any middleware you are using
but you can also get the impression it's blocked because of unclosed parens or strings
also, nrepl itself is a threaded implementation of a network protocol, you can disconnect or reconnect, no matter what the active IO is doing in one client
[ANN] Cognitect Labs' aws-api 0.8.292 https://groups.google.com/forum/#!topic/clojure/uvOzyfBrbyc
I’m running this code on Java source code from OpenJDK in a Java 11 environment:
$ clj
Clojure 1.10.0
user=> (import '[javax.tools ToolProvider DocumentationTool])
javax.tools.DocumentationTool
(let [dt (ToolProvider/getSystemDocumentationTool)]
(.run dt nil nil nil
(into-array ["-public"
"--source-path" "/Users/Borkdude/git/openjdk-jdk11/src/java.base/share/classes"
"java.lang"])))
/Users/Borkdude/git/openjdk-jdk11/src/java.base/share/classes/module-info.java:307: error: ';' expected
^
/Users/Borkdude/git/openjdk-jdk11/src/java.base/share/classes/module-info.java:309: error: ';' expected
^
2 errors
1
What’s wrong here?module-info and package-info are intentionally invalid java source filenames
such that their addition was guaranteed not to collide with existing source files
what should I do with this?
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by clojure.lang.InjectedInvoker/0x0000000800232040 (file:/Users/Borkdude/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar) to method com.sun.tools.javac.file.JavacFileManager.getJavaFileObjects(java.io.File[])
the code looks like this inside a let
:
dt (ToolProvider/getSystemDocumentationTool)
fm (.getStandardFileManager dt nil nil nil)
files (.getJavaFileObjects fm (into-array java.io.File [f]))
making it non-reflective is prob your best bet
(.getJavaFileObjects fm (into-array java.io.File [f]))
is reflective
type hint fm to the generic interface and you're probably good
fm is probably typed as the concrete actual type
(.getJavaFileObjects ^javax.tools.StandardJavaFileManager fm (into-array java.io.File [f]))
well, the warning from warn-on-reflection says:
Reflection warning, clj_kondo/Doclet.clj:62:15 - call to method getJavaFileObjects on javax.tools.StandardJavaFileManager can't be resolved (argument types: unknown)
it’s this method: https://docs.oracle.com/javase/9/docs/api/javax/tools/StandardJavaFileManager.html#getJavaFileObjects-java.io.File...-
which has File[], Path[], and String[] overrides
it does seem like it should know enough to work there but maybe the reflection stuff isn't matching componentype?
actually this works too:
files (.getJavaFileObjectsFromFiles fm [f])
without a warningI'd have to look more deeply to understand why
could maybe hint ^"[Ljava.io.File;"
could you guys help me decipher what is going on here? i got this from a thread dump, and i feel like i may have my jetty server configured incorrectly
"qtp247078080-91" #91 prio=5 os_prio=31 tid=0x00007fd0b02d1800 nid=0xea03 waiting for monitor entry [0x0000700012c87000]
java.lang.Thread.State: BLOCKED (on object monitor)
at ring.middleware.reload$reloader$fn__5707.invoke(reload.clj:10)
- waiting to lock <0x0000000789c20aa0> (a java.util.concurrent.LinkedBlockingQueue)
at ring.middleware.reload$wrap_reload$fn__5718.invoke(reload.clj:38)
at common.server$wrap_exception_handling$fn__6898.invoke(server.clj:35)
at ring.middleware.ratelimit$wrap_ratelimit$fn__5858.invoke(ratelimit.clj:50)
at ring.middleware.json$wrap_json_response$fn__5126.invoke(json.clj:87)
at ring.middleware.json$wrap_json_body$fn__5101.invoke(json.clj:44)
at ring.middleware.content_type$wrap_content_type$fn__5078.invoke(content_type.clj:34)
at ring.middleware.not_modified$wrap_not_modified$fn__5178.invoke(not_modified.clj:53)
at ring.middleware.keyword_params$wrap_keyword_params$fn__5158.invoke(keyword_params.clj:36)
at ring.middleware.params$wrap_params$fn__5196.invoke(params.clj:67)
at ring.middleware.cors$handle_cors.invokeStatic(cors.clj:171)
at ring.middleware.cors$handle_cors.invoke(cors.clj:160)
at ring.middleware.cors$wrap_cors$fn__8210.invoke(cors.clj:185)
at ring.middleware.session$wrap_session$fn__6847.invoke(session.clj:108)
at ring.adapter.jetty$proxy_handler$fn__5043.invoke(jetty.clj:25)
at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:258)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)
I think it’s a deadlock too. After reviewing some videos on C concurrency… I can see the monitoring thread in the error. I am curious though… I thought Clojure tries to avoid using synchronization locking concurrency? Is the Clojure code using some Java locking code?
i have an api being served with a series of middlewares, but i’m not sure where in this stack the problem actually is
looks like a deadlock here: https://github.com/ring-clojure/ring/blob/master/ring-devel/src/ring/middleware/reload.clj#L11
if that is actually a deadlock there should be another thread in the stacktrace in the critical section and not leaving it for some reason