Fork me on GitHub
#clojure
<
2024-03-16
>
Vatche J11:03:17

Is there a way to use dependencies in a REPL like CoderPad, other than manually loading the contents of the dependency’s files directly into the REPL?

p-himik11:03:18

Dunno what CoderPad is, but Clojure 1.12 has add-lib and add-libs functions that you can use in a REPL.

p-himik11:03:44

The come from the clojure.repl.deps namespace that's automatically included when starting the default REPl.

p-himik11:03:17

Clojure 1.12.0-alpha9
user=> (add-lib 'com.github.seancorfield/honeysql)
[com.github.seancorfield/honeysql]
user=> (require '[honey.sql :as sql])
nil
user=> (sql/format {:select :* :from :t})
["SELECT * FROM t"]

Vatche J11:03:41

https://app.coderpad.io/sandbox is an web-based coding environment. Some companies use it for live-coding interviews. Unfortunately, they’re on Clojure version 1.11.1.

p-himik11:03:06

> Some companies use it for live-coding interviews. Shame on them. :D And seems like yeah, manually copying the source over seems like the only viable approach in the case of CoderPad. But they do mention that you can email them with suggestions: > Are there any libraries or settings we missed? Feel free to <mailto:[email protected]?subject=CoderPad%20Language%20Suggestion|email us> with suggestions!

Vatche J11:03:55

Ok. I’ll give that a shot. Thank you!

👍 1
roklenarcic22:03:29

If I have a clojure.core.async go-loop that reads from a channel and executes some code, is this code executed concurrently. In other words, is a go-loop executed simulatenously on multiple threads?

p-himik22:03:51

No. go-loop is literally (go (loop ...)).

p-himik22:03:41

The same block might be executed in parallel if you execute the (go-loop ...) form itself more than once. Just in case - don't do anything computationally intensive in there without using (core.async/thread ...). The thread pool that backs go blocks is very limited and isn't meant to be executing anything long-running.

roklenarcic22:03:38

Right, but so… only a single instance of go block is running, per go invocation, (even though multiple items could be taken from channel and processed, since channel is full)?

p-himik23:03:02

Yes. It's a regular single thread that runs the code.

ghaskins23:03:06

@U66G3SGP5 while the go-loop itself doesn’t parallelize the items on the stream, it is trivial to add this using one of the pipeline primitives in core.async (for instance, https://clojuredocs.org/clojure.core.async/pipeline-async)

ghaskins23:03:23

pipeline-async just leverages the core-async thread pools for go routines, but you can also use pipeline-blocking or pipeline if you need to branch out to other pools

p-himik23:03:08

Note that the async in the name means that the function that does the work is intended to be async. Same with blocking - it's about the operation itself, not about the pipelining. So, just in case, my "just in case" comment still applies. :) If you have computationally-intensive stuff, the blocking fn should be used.

ghaskins23:03:48

Right, I didnt mean to suggest otherwise. My main point was that if you want to do more than one thing to a core.async channel at a time, pipeline* is your friend.

p-himik23:03:25

Of course, I wasn't poking at your comment, just adding info to the thread.

👍 1
roklenarcic07:03:10

Thanks for the explanation. Actually I am trying to remove core.async from some code and I am trying to make it work exactly the same, so the question of whether go-loop was parallelized or not came up.