Fork me on GitHub
#beginners
<
2023-03-03
>
chucklehead03:03:59

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?

hiredman03:03:15

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!

stantheman15:03:26

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

Chase18:03:51

I'm getting user input like so:

(print "User: ")
(flush)
(read-line)
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.

dgb2318:03:50

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

(do (print "User: ")
    (flush)
    (read-line))

dgb2318:03:48

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

Chase18:03:16

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

dgb2318:03:40

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

dgb2318:03:52

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

Chase18:03:42

Yeah, it's in my main function

Chase19:03:06

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

dgb2319:03:29

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

Chase19:03:40

Yep:

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

Chase19:03:47

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

dgb2319:03:12

or a different shell?

seancorfield19:03:52

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

dgb2319:03:55

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

dgb2319:03:14

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

seancorfield19:03:01

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

Chase19:03:22

That worked!

🎉 2
mathpunk19:03:39

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.

mathpunk19:03:24

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

mathpunk19:03:08

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

mathpunk19:03:23

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

mathpunk19:03:14

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