Fork me on GitHub
#clojure
<
2019-11-25
>
vemv00:11:17

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))))
    (Thread/setDefaultUncaughtExceptionHandler))
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

vemv00:11:00

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

hiredman00:11:54

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

vemv00:11:39

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

hiredman01:11:01

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

hiredman01:11:09

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

vemv01:11:53

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

ido12:11:02

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!

markmarkmark14:11:24

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 🙂

markmarkmark14:11:27

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

☝️ 4
zachcp13:11:48

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 http://clojurewerkz.org/, I guess you find something inspiring there

zachcp20:11:48

thanks @U0522TWDA this is a great resource and I will take a look. Right now I’m browsing https://github.com/magnetcoop/payments.stripe

👍 4
metehan14:11:18

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

kardan14:11:53

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

🍻 8
andy.fingerhut14:11:03

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.

erwinrooijakkers14:11:11

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
kardan14:11:09

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
metehan15:11:45

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

g15:11:55

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

g15:11:13

like some but for a single thing

Alex Miller (Clojure team)15:11:59

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

g15:11:16

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

g15:11:27

i’ve never ever had to explicitly return nil before

g15:11:37

what do you think?

Alex Miller (Clojure team)15:11:01

I don't understand what you're asking for

g15:11:28

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

g15:11:54

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

g15:11:16

some does what i want, but it works for collections

jumpnbrownweasel20:11:09

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?

g15:11:31

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

g15:11:43

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

sparkofreason16:11:39

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.

sparkofreason16:11:31

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?

dpsutton21:11:31

how did you default them to 8? @contact904

Eduardo Mata22:11:07

core.async is by default using 8

robertfw22:11:27

@contact904 from https://clojure.github.io/core.async/ -

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

hiredman22:11:29

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

hiredman22:11:42

like blocking operations in go blocks

noisesmith22:11:59

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

noisesmith22:11:14

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

hiredman22:11:38

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

vemv22:11:29

Likewise, setting the new flag seems recommendable (in :dev/:test builds, at the very least) https://github.com/clojure/core.async/commit/aca2b4caf195b668e0e5aba286345d5fa376b1fb#diff-04c6e90faac2675aa89e2176d2eec7d8R65

parrot 4
noisesmith22:11:58

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

hiredman23:11:08

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

sogaiu23:11:55

please elaborate if you don't mind

seancorfield23:11:29

@sogaiu So there is something shorter than this:

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

sogaiu23:11:05

so :m/my-symbol is too long?

seancorfield23:11:28

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

sogaiu23:11:49

i typically would do :wdm/my-symbol

seancorfield23:11:50

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

sogaiu23:11:46

ah good point

sogaiu23:11:04

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

seancorfield23:11:44

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

seancorfield23:11:09

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

sogaiu23:11:48

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

hiredman23:11:07

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

👍 4