Fork me on GitHub

Is the 'granularity' for pmap the lazy sequence chunk? i.e. if there's an outsized item in a chunk and all other tasks have completed, no new tasks will be started until that item completes?


Basically yes

Δημήτριος Φκιαράς09:03:25

Hello, I am looking for a function to find the index of a subvector inside a vector:

(my-index [100 20 8] [0 13 8 100 20 8 9 14]) ; 3
So far I just managed this using
(java.util.Collections/indexOfSubList (apply list [0 13 8 100 20 8 9 14]) (apply list [100 20 8]))
Is this an efficient way? Is there an alternative way to do this using vectors?

Martin Půda09:03:56

You don't have to convert:

(java.util.Collections/indexOfSubList [0 13 8 100 20 8 9 14] [100 20 8])
=> 3

🤫 2
Δημήτριος Φκιαράς09:03:19

Thanks! I don’t know how I missed that!


As I dont like to delve back to java (the documentation drives me crazy). I tried a Clojure only which criterium showed gave same speed as java indexOf. Evaluation count : 3541492380 in 60 samples of 59024873 calls. Execution time mean : 15.004989 ns Execution time std-deviation : 0.082944 ns Execution time lower quantile : 14.851435 ns ( 2.5%) Execution time upper quantile : 15.212629 ns (97.5%) Overhead used : 2.011556 ns Found 2 outliers in 60 samples (3.3333 %) low-severe 1 (1.6667 %) low-mild 1 (1.6667 %) Variance from outliers : 1.6389 % Variance is slightly inflated by outliers


I'm getting user input like so:

(print "User: ")
Because I want the terminal to output: User: <what the user input after hitting enter> But what is happening is it first prints out User: and then waits for the input but then after the user presses Enter it changes too: <what the user input> without the "User: " part at the beginning. Do you know how I can fix that. I don't want to use println without the flush because I want the "User: " to appear on the same line as their input.


I just tried it out in a standalone repl (calva) and it worked like this:

(do (print "User: ")


I think it has something to do with print and flush returning nil?


Hmmm, I'm still getting the same unwanted behavior even when wrapping it in a do


That's confusing! It works for me with a compiled jar too


You did evaluate your whole do right? Or you put this into your main function?


Yeah, it's in my main function


(defn -main []
  (println "Welcome to ChatGPT CLI")
  (print "Please enter a prompt: ")
  (loop [prompt (read-line)]
    (let [resp   (response (request prompt))
          resp   (:content (last @messages))]
      (println "ChatGPT response:" resp)
      (print "User: ")
      (recur (read-line)))))


And you have tried just the example code that we discussed? And that didn't work either?



λ ~/projects/clojure/chatgpt-cli : clj -M -m chatgpt-cli.core
After input:
λ ~/projects/clojure/chatgpt-cli : clj -M -m chatgpt-cli.core
My input
 λ ~/projects/clojure/chatgpt-cli :


I am about to switch to trying babashka so I will see if I have the same behavior there


or a different shell?


This is a terminal or rlwrap issue I think...?


That's not what Chase is trying to do @U04V4KLKC


it works just fine with my setup. Seems like the terminal/shell is weird


I remember this coming up before and someone suggesting a change to .inputrc I think?


That worked!

🎉 2

I am interacting with an API endpoint that sends Content-Type = binary/octet-stream 😱 First time working with that kind of thing. I’m realizing, oh yeah, I’m trying to automate something where if I were doing it manually, I would click a download button, but I’m trying to avoid doing that 1400 times.


Goal: Get the data from the :body of the response, ✌️spit ✌️ it to a file with a filename “artifact-:id”


Obstacle: Some of those artifacts are probably missing so I better handle 404 errors


I’ve been using dakrone’s clj http kinda like this:

(defn call-with-token [url]
  (http/get url {:headers {"PRIVATE-TOKEN" private-token}}))
and I guess I need to wrap an exception handler to catch the 404s


your link brings up something I’ve wondered…. slurp and some functions from can read right from a URL, I gather, but can they do it when there’s authentication needed? I need that PRIVATE-TOKEN header in order for the api to talk to me