Fork me on GitHub
#clojure
<
2019-09-09
>
Mark Addleman00:09:38

I'm using metosin's spec-tools (v0.10.0) for coercion. The following code snippet is not producing what I would expect:

(st/coerce
    (st/spec {:spec (s/cat :op (st/spec {:spec keyword?}))})
    ["a"]
    st/string-transformer)
Yields ["a"] - I was expected [:a] Does spec-tools support s/cat and the spec regular expressions?

ahungry04:09:09

in clojure/java interop, does the RT in clojure.lang.RT = runtime? Is there any way to have 2 or more distinct clojure runtimes going at once in clojure itself, or in java? Essentially, I want to "boot" a clean clojure instance with nothing initialized in one

Alex Miller (Clojure team)04:09:02

RT = runtime, and no, or not easily

Alex Miller (Clojure team)04:09:32

boot pods do give you some level of this and there are other libs that do this to some degree

Alex Miller (Clojure team)04:09:52

you really need at least classloader isolation

ahungry04:09:50

thanks - is there a good spot to look at the launch point/source code of any threads a clojure RT has executing? (what threads does it run, and is it possible to manually invoke them?) I'm not making a "production" solution, just having some fun tinkering with clojure/java/jni and forking at a C level. I'm as far as passing an arbitrary fn to to the forked jvm and getting the result back to the parent via external means (file etc.), however in my fork of the JVM, any calls to clojure.core/eval, whether executed directly from RT in java, or via my IFn.invoke() passed in function, it will break there

ahungry04:09:15

i'm assuming something runs in the clojure runtime that is required for calls to "eval" to work on the java/jvm side

ahungry04:09:30

whereas it isn't required for other primitives like (+ 1 2 3) or (prn "Hello world")

ahungry04:09:17

(and obviously my fork copy will be missing all the previously launched threads)

Alex Miller (Clojure team)04:09:03

the RT does not run any threads - you run the threads :)

Alex Miller (Clojure team)04:09:57

well, I guess future and agent do use thread pools for execution, so those and things that rely on them (like pmap) do potentially start threads

Alex Miller (Clojure team)04:09:22

but the RT is mostly started by loading the RT class via the different entry points

dominicm05:09:37

@m131 you might be interested in shimdandy, which I recently played with and updated a library to make very easy to use https://github.com/SevereOverfl0w/clj-embed

ordnungswidrig10:09:28

Does anyone now a simple way to have clojure.tools.logging log the ex-data when backed by logback? (It’s just logging the message and the stacktrace)

ataggart21:09:31

I vaguely recall this being an issue of logback's implementation specifically calling .getMessage. Calling .toString would have included the ex-data.

user=> (ex-info "message" {:data 123})
...
user=> (.getMessage e)
"message"
user=> (.toString e)
"clojure.lang.ExceptionInfo: message {:data 123}"

ataggart21:09:49

I assume there's some way to customize how logback emits exceptions.

ordnungswidrig07:09:44

You can configure it but to my knowledge only the size of the stacktrace printed.

ordnungswidrig07:09:24

Ok, there is ThrowableHandlingConverter 🙂

borkdude11:09:15

why doesn't string/index-of have a ^long return type hint? because that's not possible with primitives maybe?

4
borkdude11:09:09

@m131 @dominicm depending on the use case, there's also https://github.com/Raynes/clojail (of which I have an updated version on Github somewhere)

borkdude11:09:31

not sure what your use case is

ahungry12:09:16

Nice, ill take a look

lread12:09:24

I remember reading that someone was looking at bringing 4clojure up to date but needed to update clojail, @borkdude do you think your update might do the trick? Or maybe your clj-embed @dominicm?

borkdude12:09:27

@lee I used clojail to run code from clojuredocs to verify specs in speculative: https://github.com/borkdude/speculative/blob/master/deps.edn#L15

borkdude12:09:40

for the 4clojure kind of use case, eventually sci may also be used: https://github.com/borkdude/sci/ that could even run client-side and server-side

borkdude12:09:28

but it's not on par with everything that is needed in 4clojure solutions probably

lread13:09:21

Ah... here’s where I was reading about 4clojure progress: https://github.com/clj-commons/meta/issues/2

fabrao18:09:23

Hello all, I´m building clojure program to process video stream into many ways. I want to distribute this each frame to many processing specific processors, like one for saving it to database, other for doing some OCR, other to detect objects in image, and so one ... How do you think it´s the best way doing this? core.async? Producer->Consumer events? ReactiveX?

noisesmith18:09:31

core.async isn't good for directly using with IO or CPU intensive tasks (but you can use it in combo with the core.async/thread macro to avoid the issue), I think the simplest answer here is a concurrent queue plus threadpool, eg. what an ExecutorService provides

noisesmith18:09:58

use core.async if there are complex coordination conditions to implement after the parallel processing completes

lukasz18:09:29

Claypoole is incredibly useful for creating threaded code, avoids diving into ExecutorService https://github.com/TheClimateCorporation/claypoole

noisesmith18:09:26

does it have a queue mechanism? I've used it for "pmap" type stuff but not that

noisesmith18:09:31

the docs make me think you'd need to pretend your requests / tasks were a lazy-seq, that's an antipattern

lukasz18:09:35

I think Claypoole's pmap is ordered, as it also has a upmap variant (order by whoever returns first)

noisesmith18:09:48

right, but it consumes a seq, that's the problem to me

noisesmith18:09:22

(the ordering aspect is a smaller problem)

lukasz18:09:24

Right. I guess it was never an issue in our use case, as we use it for parallelizing IO operations

noisesmith18:09:28

maybe one of these weekends I'll make a PR on claypoole for a queue based parallelization that handles eg. binding conveyance etc. (which is where executorservice becomes less convenient if you need it...)

fabrao18:09:07

I used claypoole in other project, I´ll try to use with it too

MatthewLisp18:09:46

Hey people who have used another languages to create API's, is the term "handler" something common ?

lukasz18:09:33

Quick google for "request handler" seems to point at "yes" as the answer 😉

aengelberg20:09:17

Why does iterate’s docstring say that f must be free of side-effects?

Alex Miller (Clojure team)21:09:52

because it doesn't make any promises about when f is called, or how many times its called

Alex Miller (Clojure team)21:09:51

a particularly subtle aspect is that the return value from iterate is actually both seqable and reducible and the latter does not use any cached values of the seqable

Alex Miller (Clojure team)21:09:36

it's pretty unusual to use the result in both contexts (usually you do one or the other) but you could construct some pretty weird results in combination with side-effecting functions

Alex Miller (Clojure team)21:09:35

if you want to do this with side-effecting things, repeatedly or run! are prob better

borkdude21:09:02

the docstring has been like this since at least 2009, when reducible wasn't a concept yet?

Alex Miller (Clojure team)21:09:35

yep, but we took advantage of it when iterate was reworked in 1.7

Alex Miller (Clojure team)21:09:27

I also did a lot of review of 100s of existing uses of it

Alex Miller (Clojure team)21:09:54

to convince myself that people largely did as they were commanded :)

seancorfield21:09:43

(let [stuff (iterate #(do (println 'N %) (inc %)) 0)] (println (doall (take 5 stuff))) (reduce (fn [n i] (if (< 5 i) (reduced n) (+ n i))) 0 stuff))
N 0
N 1
N 2
N 3
(0 1 2 3 4)
N 0
N 1
N 2
N 3
N 4
N 5
15
user=> 
🙂

hiredman22:09:29

https://clojure.atlassian.net/browse/CLJ-1906 is somewhat related to iterate, in that when you state the problem a common refrain is "just use iterate" and then you have to say "oh, but iterate's doc says no side effects"

8
Alex Miller (Clojure team)23:09:33

it is something I frequently forget, then remember :)