Fork me on GitHub

What's a clean way to fail the test suite (`lein test` ) if an auxiliary thread threw an exception? I tried:

(-> (reify Thread$UncaughtExceptionHandler
      (uncaughtException [_ thread ex]
        (is false (pr-str ex))))
however this doesn't fail the build. I do see FAIL in ()... in stdout, but build passes. I guess it's some sort of race condition, as the exception can happen between a test is finished and the next one is run


...maybe (System/exit 1) for simplicity


It isn't a race condition, the testing machinery makes use of dynamic bindings and the thread your exception handler is run on doesn't have the bindings setup to report a failure


yup, had guessed that was the case Do you know of a (clean) fix that leverages these bindings? Otherwise I think I settled for System/exit within my DefaultUncaughtExceptionHandler


The best thing to do is to either test on the effects (if a background thread I supposed to write to the DB check the DB), or have other threads actually report their results instead of firing and forgetting


If you can get an exception in a random thread and it indicates a problem with your program. and you test suite doesn't fail except for watching specifically for exceptions in other random threads, it means you are missing a test for whatever the behavior of that thread was


Good observations! My intention was to have this a safeguard in my test setup, rather than use it actively as a means for coding sloppier tests This specific library has quite a lot of intrinsic concurrency (`go` blocks etc) so it seems particularly needed here


Hey have anyone ever benchmarked carmine vs lettuce in clojure?

Jakub Holý (HolyJak)12:11:19

Fun fact:

(.toEpochMilli (java.time.Instant/MAX)) ;; => ArithmeticException: long overflow
Java FTW!


This makes sense and is documented in the javadoc for .toEpochMilli

Jakub Holý (HolyJak)14:11:22

As I user I am surprised I can make Instant so far in the future that long cannot hold it 🙂


it can hold it in seconds, which is what Instant uses

☝️ 4

I am looking to write a clojure wrapper for a REST api. Does anyone have any examples of existing clojure wrappers that they find to be truly excellent in some way?

Jakub Holý (HolyJak)14:11:34

You want to create a Clojure client calling a remote REST? I would have a look at, I guess you find something inspiring there


thanks @U0522TWDA this is a great resource and I will take a look. Right now I’m browsing

👍 4

Hi, I am using clojurescript since 5 months. I am very happy with the experience. On server side I use Elixir. I think without knowing JavaScript using ClojureScript would be very very hard. Is it same for Clojure? Without knowing any Java can I handle Clojure or I better stay in Elixir&Erlang


In a similar way Clojure and ClojureScript does not try and hide the host

🍻 8

I don't think you need to be an experienced Java developer to take advantage of Java libraries from Clojure. You do need to know how to find useful libraries, and read and interpret their API documentation, so you need at least some of the terminology of Java to be familiar and understood.


You’re able to use Erlang libraries from Elixir using native Elixir syntax quite easily, but you’ll need to learn Erlang syntax and semantics to read and understand Erlang API docs. Beyond that, I haven’t learned Erlang in full, and I haven’t had any issues using Elixir for everything. You mostly just need to know the mapping from Erlang to Elixir syntax.

lisphug 4

I started Clojure at work with an Erlang background. Didn’t know much than that I disliked the JVM 🙂 But I totally switched. Today I love Clojure and benefit from the JVM. And you can come fairly far without having to deal too much with Java 🙂

👍 4

Then I am going to give a deeper look 🙂 . I am in love with Erlang's BEAM but after getting used to lisp syntax I am missing it alot when I code in other languages.

Noel Llevares22:11:00

Isn’t Elixir a LISP with a Ruby-ish syntax? 😛


this is eluding me this morning for some reason.. what would be preferable to (when [x (potentially-nil)] x)?


like some but for a single thing

Alex Miller (Clojure team)15:11:59

or ? what you want to happen when it's nil?


yeah i could do or nil, seemed a little ugly though


i’ve never ever had to explicitly return nil before


what do you think?

Alex Miller (Clojure team)15:11:01

I don't understand what you're asking for


sorry, i want to either return the value if it’s truthy or nil


also i’m only just now realizing this isn’t the beginners channel. sorry


some does what i want, but it works for collections


Sounds like you may not need it, but it is possible to check for nil on a single item with some? (which is different than some for collections).

Alex Miller (Clojure team)15:11:42

so are you specifically trying to avoid false?

Alex Miller (Clojure team)15:11:27

is that logically what you want?


actually.. man this is silly, i’m reading from a map and so it would of course be nil if it doesn’t exist.


sorry. appreciate the help though. i need more coffee.


On Java->Clojure interop and classloaders: If the Java environment requires that a specific classloader be set before calling Clojure, does that imply that we always need a "native" Java class definition to handle this as opposed to doing something like gen-class? Or is there some way to make this work in Clojure with no Java code?

Alex Miller (Clojure team)16:11:37

I assume this refers to your prior questions about KSQL. Because that env seems to have some classloader expectations, I'm not sure that there is any way to avoid doing something in Java. But not knowing anything about their setup, it's hard to say.


They're isolating the classpaths for different user-defined functions in KSQL, so I'm guessing you're right, that the Java step is going to be required.

Eduardo Mata21:11:21

Howdy, How can I add more native threads (default 8 to my project?


how did you default them to 8? @contact904

Eduardo Mata22:11:07

core.async is by default using 8


@contact904 from -

go blocks are dispatched over an internal thread pool, which defaults to 8 threads. The size of this pool can be modified using the Java system property `clojure.core.async.pool-size`.


there are cases when you want to up that, but more often if you have to up that it indicates an issue with your code


like blocking operations in go blocks


the pool size was deliberately made smaller to expose errors in using core.async that used to happen rarely during dev, then happen under load when deployed


it's better to rewrite your core.async code not to block the pooled threads


if you are just starting out with core.async you almost certainly do have places where you are doing blocking operations in go blocks


Likewise, setting the new flag seems recommendable (in :dev/:test builds, at the very least)

parrot 4

that's great, of course there are a lot of other ways to block, but that at least reduces the number of gotchas


it is wild to me how much demand there is for some lightweight way to make ns aliases to make namespaced keywords shorter to type


please elaborate if you don't mind


@sogaiu So there is something shorter than this:

(alias 'm  (create-ns 'ws.domain.member))


so :m/my-symbol is too long?


No, but people think :ws.domain.member/my-symbol is too long


i typically would do :wdm/my-symbol


and they want an easier way to alias ws.domain.member to m than the code I gave.


ah good point


thanks -- i have been avoiding :: because i ran into troubles with it before


And being able to change the alias line once per namespace is less work (and less error prone) than changing every reference to a keyword with that qualifier...


:: is fine. I use it a lot with specs.


i'm not saying there is a problem with it -- i just had problems -- that's most likely my head containing the problem 🙂


yeah, I guess using namespaced keywords, I never find myself feeling constrained in some way by how many characters they are

👍 4