Fork me on GitHub
#clojure
<
2021-10-26
>
Alan Thompson01:10:30

Does anybody here use `bat-test` from Metosin?  I'm trying to figure out how to stop the capture of unit test output.

juhoteperi06:10:36

It is quite likely no one is using it. The output capture is implemented by eftest: https://github.com/weavejester/eftest#output-capturing But I don't remember how those options are passed in with bat-test, or if there is a support. Looks like bat-test impl passes the whole opts map to eftest, with some changes, but e.g. from boot task there probably isn't way to add extra options properties.

didibus05:10:20

Kind of surprised to see Clojure beat Go at making 500 concurrent http get requests: https://gist.github.com/didibus/543076be0499c1256024dee5853ad592

jjttjj06:10:52

I'm kinda surprised http://clojure.org just allows 500 x n fast as possible requests. Is it returning 200 response codes every time? Not sure how/if error responses would effect performance though

FiVo08:10:04

Are you sure that keepalive might not come into play in this case. It seems to be enabled by default for http-kit https://http-kit.github.io/client.html

FiVo09:10:50

But also seems to be the case for Go.

Alex Miller (Clojure team)13:10:55

http://clojure.org is static files served on cloudfront so you're at the whim of whatever edge cache you're hitting. why http and not https? former should be redirecting to the latter.

Alex Miller (Clojure team)13:10:21

also keep in mind that we're paying for each of those requests :)

😝 1
amalantony13:10:03

https://reqres.in/ is perhaps a better endpoint to benchmark with.

jjttjj14:10:12

Yeah I couldn't come up with a wording for "it might not be the best etiquette" that captured the magnitude of the etiquette violation I wanted to convey

didibus15:10:45

Sorry @U064X3EF3 I should switch it to http://golang.org and make El Goog pay instead haha

😆 1
Alex Miller (Clojure team)15:10:11

I mean, it's pennies, but maybe :)

didibus15:10:21

https://golang.org Clojure gets 451ms vs 1.864s on GO

didibus16:10:47

Tried to set Go to use HTTP/1.1 only as well, since it was also using HTTP/2 and http-kit doesn't, but I get similar results either way.

amalantony19:10:18

@U0K064KQV Sounds like a good story for Hacker News.

didibus19:10:38

Haha, I'm scared of the comment section of such a thing 😛

Nom Nom Mousse08:10:55

Will a (reset! my-atom myval) continue until successful? Or might it stop trying after a while?

vemv08:10:51

Unless I missed sth more obvious, it looks like atoms ultimately delegate to https://github.com/openjdk-mirror/jdk7u-jdk/blob/f4d80957e89a19a29bb9f9807d2a28351ed7f7df/src/share/classes/sun/misc/Unsafe.java#L863-L865 (via AtomicReference) not sure of how to jump from Java code to C code :)

1
leonoel08:10:00

reset! is a volatile variable assignment, there's no way it can fail

vemv08:10:16

I don't think volatile == CAS, for one thing they're different concepts/mechanisms in Java else clojure's Atom would look a lot more like clojure's own volatile!

Nom Nom Mousse08:10:41

I'm using reset! from a child process to send the result back to the main process so the main process can handle the result. I want to be sure the result gets handled eventually.

leonoel08:10:56

reset! doesn't use CAS

vemv08:10:43

@U0232JK38BZ you can be damn sure reset! will eventually succeed, unless perhaps you intentionally place a scenario of extreme contention I thought this was more of a 'fun' theoretical question

🙏 1
vemv08:10:10

@U053XQP4S you're right, I was chasing the path for swap! not reset! (the question made me think of retries which brought swap! to mind)

👍 1
Nom Nom Mousse08:10:59

But will every reset! be handled by the watcher that watches the atom that is reset?

restenb12:10:40

is there a way to specify List<String>as type hint?

p-himik12:10:16

The <String> part does not exist in runtime or during compilation. Just List should be enough.

athomasoriginal13:10:41

How do people like to determine when a function should return nil as opposed to an empty coll ? TMK it’s about choosing a return type and remaining consistent about it. Perhaps there is more to it though? :thinking_face:

pavlosmelissinos14:10:23

In my experience, nil and an empty collection are usually the same, semantically speaking, so I don't bother with consistency in this particular case.

pavlosmelissinos14:10:07

Meh, I worded that poorly... I meant they're semantically the same as output types, not in every possible scenario. As in, should it matter whether filter with no matches gave back nil vs an empty collection? I don't think so

Apple14:10:28

false/nil is like -1 to me [] is like 0 to me everything else is like a positive integer to me

pavlosmelissinos15:10:16

Ι don't get the analogy. Can you elaborate?

pinkfrog14:10:19

It seems to me add-libs still does not exist in tools.deps.alpha ? How can I use it?

pinkfrog14:10:24

Yes. Will it the add-lib3 branch ever be merged?

pavlosmelissinos14:10:30

Until it is you can use the branch as a git dependency

dharrigan15:10:33

I have an add-libs in my deps.edn too, it works fine, just just have to require in the namespace

dharrigan15:10:36

then you can use it

dharrigan15:10:01

note 'tho, the note at the bottom about using a dynamic class loader.

pinkfrog15:10:48

Not sure how the “if we’re starting other processes via aliases ;; such as a socket REPL or Cognitect’s REBL etc” actually means.

pinkfrog14:10:24

Yes. Will it the add-lib3 branch ever be merged?

dpsutton14:10:48

The core issue remaining is related to the dynamic classloader you need to make it work correct?

Alex Miller (Clojure team)14:10:36

there are several open questions

👍 2
vlaaad15:10:42

Btw I'm using add-lib3 branch all the time. Very useful!

1
Alex Miller (Clojure team)15:10:49

do you use it just to try stuff, or do you later add those libs to your deps.edn?

vlaaad15:10:33

Both, i.e. there are times when I try some lib to see if it works for me, and if it is, I'll add it to deps.edn; and there are times when it's for a throwaway code that gets deleted

dharrigan15:10:50

ditto! Very useful for trying things out, then if the experiment works, to incorporate it into my deps.edn

vlaaad15:10:58

Actually, I usually add lib to deps.edn and then call add-libs with that lib, so it's both available at the repl without restart and cursive indexes it to provide autocomplete

Alex Miller (Clojure team)15:10:35

one thing we've wondered about are ratio of "temp experiment" to "know you need" and for the latter, whether it would be useful to have • runtime libs -> persist to deps.edn or • sync runtime from deps.edn (so you'd modify deps.edn, then sync) options instead

Alex Miller (Clojure team)15:10:16

lots of thorny questions in both cases but just thinking about workflows

dharrigan15:10:27

That's a great insight into the thoughts around the situation 🙂 Thanks for sharing.

Ben Sless16:10:06

Don't ever quote me crediting CL, but the ability to interactively "freeze" or image those dependencies could be useful, i.e. the relationship between deps.edn and the runtime can be bidirectional

Alex Miller (Clojure team)16:10:20

this is generally, very hard to represent. any particular classpath for a project is created from a set of root deps, optionally some aliases that modify that, and then many transitive deps. the versions selected are dependent on that set of deps at classpath calculation time. adding new libs at runtime as new top-level deps is a best effort exercise (you can't "upgrade" or change a version of something you've already included, and you are adding that new dep and its transitive deps in the context of a set of "pinned" versions for all transitive deps. there are lots of ways to get different answers than if you'd started fresh and/or invalid combinations.

Alex Miller (Clojure team)16:10:00

that sloppiness is probably ok if you mostly understand your deps tree and and how this can go wrong (if you add new deps enough times, you will eventually fall over), but that is hard to communicate to a broad range of users. you also want to avoid leading people into this as a way to start an app, so it should be a "repl-only" thing

👍 2
Ben Sless16:10:16

wait, I still didn't get to the point where you replace git with a series of edits in a graph database 🙂

Ben Sless16:10:54

But enough spoilers for the next blog post 😛

Alex Miller (Clojure team)16:10:53

maybe we should call the function try-lib instead or something to indicate it's potential for failure :)

Yehonathan Sharvit16:10:41

Hello macro friends! I'd like to write a macro called go-inst that works like a go macro with a tweak: calls to <! >! and alt! and alts! need to be wrapped in a piece of code. For instance:

(go-inst {:context "my-context"}
         (let [c (chan)] 
           (>! c :data)
           (<! (chan))))
Should be macro expanded to:
(go 
  (let ([c (chan)] 
        (do 
          (println "entering my-context")
          (let [val (>! c :data)]
            (println "leaving my-context")
            val))
        (do 
          (println "entering my-context")
          (let [val (<! c)]
            (println "leaving my-context")
            val)))))

Yehonathan Sharvit16:10:44

I need also to support nested go-inst with different contexts! My question is: what's the simplest way to write the code for this macro? Should I use clojure.walk or clojure.zip? Why?

isak16:10:06

I would think just a normal recursive function, since that would make it easy to control your context.

phronmophobic16:10:48

I would use clojure.zip along with following as the zipper:

(defn clj-zip [obj]
  (z/zipper #(and (seqable? %)
                  (not (string? %)))
            seq
            (fn [node children]
              (let [children (remove #{::delete} children)]
                (if (map-entry? node)
                  (vec children)
                  (into (empty node) children))))
            obj))
you can then walk the tree with something like:
(loop [zip (clj-zip code)
       ctx {}]
  (if (z/end? zip)
    (z/root zip)
    (recur (if (something? ctx (z/node zip)
             (-> (z/edit zip f)
                 z/next)
             (z/next zip))
           ctx)))
It might be overkill for your example, but it's a general approach that has worked for me in the past.

Yehonathan Sharvit17:10:46

Why zip is better than walk for my use case?

phronmophobic18:10:03

hmmm, it might not be. If it's likely that you'll extend it in the near future, then it might

didibus18:10:19

I never thought of using zip for that. But I guess it lets you go up/down, left/right the tree. I might have to try it on a macro in the future

phronmophobic18:10:37

If you need to accumulate context as you walk up and down the tree, then it's easier with zippers

phronmophobic18:10:58

I've seen people do it with prewalk/postwalk and atoms, but I prefer the zipper approach

didibus18:10:18

I've always used walk normally.

phronmophobic18:10:17

Right, but then you can't use information from parent nodes, only child branches. For analyzing code, the context is usually provided by the parent nodes.

Yehonathan Sharvit18:10:46

In my case I definitely need the context

p-himik18:10:15

Can you elaborate? Seems like you just need to know the {:context ...} map, which is a different kind of context - you will know it just because go-inst is something you control. I'm 95% certain regular walk will work wonderfully in your case given that you seemingly need to just replace a particular form with a wrapped version of the same form.

2
Yehonathan Sharvit19:10:06

With walk, I'll need to find a way not to wrap with both contexts the <! of the inner go-inst. With zip it seems that it will work like this with no effort

Yehonathan Sharvit19:10:12

But I might be wrong

phronmophobic20:10:41

That's only a problem with prewalk, but you can just use clojure.walk/postwalk (assuming I understand your comment correctly).

Yehonathan Sharvit01:10:01

If I use postwalk I won't be able to differentiate between forms that were part of go-inst block and rewritten as a go block and forms that were orginally part of of go block

phronmophobic02:10:58

Not sure I follow. I might need an example. Wouldn't the following work?

(defn go-inst* [ctx body]
  (clojure.walk/postwalk (fn [form]
                           (if (and (list? form)
                                    (#{'<! '>!} (first form)))
                             `(do
                                (println ~(str "entering " (:context ctx)))
                                (let [val# (~(first form) ~@(rest form))]
                                  (println ~(str "leaving " (:context ctx)))
                                  val#))
                             form))
                         body))

(defmacro go-inst [ctx & body]
  `(go
     ~@(go-inst* ctx body)))

Yehonathan Sharvit08:10:13

Let me clarfify what I mean with an example:

(go-inst {:context "my-context"}
                                (let [c (chan)] 
                                  (>! c :data)
                                  (<! (chan)))
                               (go-inst {:context "your-context"}
                                (let [c (chan)] 
                                  (>! c :data)
                                  (<! (chan)))) )

Yehonathan Sharvit08:10:31

Is macro expanded to:

(clojure.core.async/go
 (let
  [c (chan)]
  (do
   (clojure.core/println "entering my-context")
   (clojure.core/let
    [val__12648__auto__ (>! c :data)]
    (clojure.core/println "leaving my-context")
    val__12648__auto__))
  (do
   (clojure.core/println "entering my-context")
   (clojure.core/let
    [val__12648__auto__ (<! (chan))]
    (clojure.core/println "leaving my-context")
    val__12648__auto__)))
 (go-inst
  {:context "your-context"}
  (let
   [c (chan)]
   (do
    (clojure.core/println "entering my-context")
    (clojure.core/let
     [val__12648__auto__ (>! c :data)]
     (clojure.core/println "leaving my-context")
     val__12648__auto__))
   (do
    (clojure.core/println "entering my-context")
    (clojure.core/let
     [val__12648__auto__ (<! (chan))]
     (clojure.core/println "leaving my-context")
     val__12648__auto__)))))

Yehonathan Sharvit08:10:40

While it should be expanded to

(clojure.core.async/go
  (let
    [c (chan)]
    (do
      (clojure.core/println "entering my-context")
      (clojure.core/let
        [val__12648__auto__ (>! c :data)]
        (clojure.core/println "leaving my-context")
        val__12648__auto__))
    (do
      (clojure.core/println "entering your-context")
      (clojure.core/let
        [val__12648__auto__ (<! (chan))]
        (clojure.core/println "leaving your-context")
        val__12648__auto__))))

p-himik08:10:39

If you need nesting where inner go-inst completely supersedes the outer one, I think you can just leave any calls to go-inst in your postwalk function as they are.

p-himik08:10:39

If you need to be able to replace just some parameters (assuming there can be more than just :context), then you can change the go-inst form in your postwalk function so its argument is (merge outer-params inner-params).

Yehonathan Sharvit09:10:42

How can I leave any calls to `go-inst` in my postwalk function as they are?

p-himik10:10:52

Just check that the first item of a list is go-inst and ignore that list.

Yehonathan Sharvit13:10:49

hmmm. I need to think about it

Joshua Suskalo20:10:16

I'd like a sanity check: there's no stdlib function that does this, right?

(defn- update-some
  [m k f & args]
  (if-some [res (apply f (get m k) args)]
    (assoc m k res)
    (dissoc m k)))

p-himik22:10:28

Indeed, there's none.