Fork me on GitHub

I’m not sure how exactly to ask this question but the gist is that I have a program that is a loop, that is a chat bot, so it sits and loops and listens to input and responds, pretty starightforward. Doing REPL driven development on it has been challenging because when I run the listening loop it hangs the REPL


is there a way to async that loop in the “background”


and then i can poke and and update a function it calls


to have a more interactive experience?


one option to consider is that the bot and the repl can listen to different file descriptors, either because you have multiple connections to one repl process, or you use a dedicated pipe/fifo - a question of making an alternate binding for *in* connected to a different tty


(a process with multiple repl connections already makes multiple *in* bindings for you)


generally a loop will call some function with some kind of message and then recur. from the repl you would want to not start the loop but just call the function that handles the message


kind of a "functional core, imperative shell" type thing. top level you have a loop which takes a message from a socket/web endpoint/queue/what have you and then does actions based on it, and then back to the top of the loop


i’d love to be able to poke at it while it’s running the loop and getting stuff from the server


in that case i’d be passing my own messages in yeah?


i think it’s waiting on a channel for input


(a/<!! event-ch)


in go i would call this as a go routine


and it wouldn’t block anything while it did its thing


core async has go routines? woah


Hi is there an iterate that allows for side effects?


am I looking for doseq?


^ this runs but the result used for rand-nth is fixed


Is there a function or a better way to do what I want.? Am trying to create a simulation of when a factory will refill its stock. So (def days-store1 [2 3 3 4 4 5 5 6]) is saying after there is a 1/8 chance that after 2 days, there is a need to restock. And then it undergoes a renewal process. So it any of those number of days in days-store1 are equally likely again

replied to a thread:

Is there a way I can do (take-while #(>= 1280 %) (reductions + (repeatedly #(rand-nth [1 2 3 4 5])))) but still have rand-nth do its side effect with each iteration? Like is there another something else I can use instead of take-while

Dimitar Uzunov12:04:08

making a jar file for deployment

💯 2

Thanks yes I could talk quickly about it showing an example. I was trying to stay away from deployment as I wanted to create a separate video on it 🙂

Dimitar Uzunov12:04:09

it is more of a build phase anyway 🙂

👍 1
✔️ 1
Umar Daraz12:04:03

backend and frontend routing may be

💯 1

Thanks. Yes routing is something I want to cover but I'm confused to what depth? I do plan to add a simple (case (:uri request).. router in my jetty handler to explain the flow of how routers work at their core. I mostly tend to use reitit as it's quite nice on both backend and frontend, do you think I should cover those to setup separately? Or are you thinking more along the lines of a single shared router between both frontend and backend?

Umar Daraz13:04:40

I m thinking of separate routing setup for backend and frontend. I don't know that shared routing setup is even possible. If it is possible, would love to see this setup. Im thinking in the lines that, e.g. in nodejs/react app, we mostly add experess and react router at the start. because even a smallish app tend to have few pages on front end and few crud operations on backend.


> I don't know that shared routing setup is even possible. > If it is possible, would love to see this setup. It's definitely possible with reitit, I don't have much experience with it but it would be a great way to learn and document. I would love to do this separately!! Thanks


> Im thinking in the lines that, e.g. in nodejs/react app, we mostly add experess and react router at the start. > because even a smallish app tend to have few pages on front end and few crud operations on backend. Yes that is indeed true, but with adding routers do you think I need to talk a bit about content negotiation/encoding, middlewares or maybe interceptors too? :thinking_face: Edit: Maybe that would be a bit too much haha. I'll think about the most minimal example I can whip up with reitit

Umar Daraz13:04:30

Yeh indeed, negotiation/encoding and middleware come into play. And it may drag the direction to library usage, instead of minimal setup. May be you can have another screen cast, that is more involve with routing after the setup one

🚀 1
💯 1

> May be you can have another screen cast, that is more involve with routing after the setup one Yes looks like that would be best! Thanks for your suggestions and feedback, super appreciate it 😄 ^_^

💯 1
🙏 1
Umar Daraz13:04:50

Here how i setup a minimal reitit example. May be it can be further simplify.

(def app
     ["/scramble" {:post  scramble-handler}]]
    {:data {:muuntaja m/instance
            :middleware [muuntaja/format-middleware]}})
    (ring/create-resource-handler {:path "/"})

🙌 1
Umar Daraz13:04:46

thanks @U013MQC5YKD looking forward to the screen cast. cljs

bananadance 1

Lovely! I was thinking something very similar, but I also understand that this can get really daunting for someone quite new 🙈


> looking forward to the screen cast. Thanks haha, I'll be sure to ping you once I have it up 🙂nyantocat

Umar Daraz13:04:06

Yes pls do. I m fairly new in clojure land, And when I was try to setup my project, I was not able to find such screen cast. So I m sure, it will help a lot of new comers

awesome 1
💯 1
🙌 1

I had the exact same experience! Trying my best to fill in this assumed gap, I already have a few beginner friendly clojure videos up here: If you're interested in checking it out 🙂

Umar Daraz13:04:48

🙌 wow Im sure I will go through each of these videos one by one. thanks of making and sharing, 🎯

bananadance 1
🥳 1

Thanks a lot this means a lot! sharkdance 🙏

Endre Bakken Stovner14:04:41

In the below code the let only differs for the outer loop.

(for [[rulename jobs] (group-by :in-rule jobinfo)
        job jobs
        :let [{:keys [params shell script]} (rules rulename)]]
Still, is the let computed anew for each inner iteration?


to find out, you could embed a (do (println "hey") (rules rulename))


but you can also move the :let above the job jobs line

💯 2

user=> (for [a (range 1 5) :let [b (inc a)] c (range b)] c)
(0 1 0 1 2 0 1 2 3 0 1 2 3 4)

Endre Bakken Stovner05:04:36

Had no idea I could move the let. Thanks!


Hi Everyone, how would yall approach a problem of generating a list of numbers that looks like [0 0 2 0 2 0 0 0 2 .... ] where the interval between the 2 are randomly chosen. Perhaps using something like rand-nth [2 2 3 4 5]


(take 100
       (interpose 2 (map #(repeat % 0) (repeatedly #(rand-nth [2 2 3 4 5]))))))
Something like this?


@UJRDALZA5 Wow yes, this is what I wanted! 😄 Actually my previous question was me trying to take a immediate step to get this


i'd probably make a lazy seq that would compute the random interval, put that many 0's and a 2, and then cons onto the "recursive" call

Elliot Stern15:04:50

mapcat seems useful


TIL replicate


Me too. But repeat is favored over replecate.


replicate is deprecated


Every element in the sequence basically has a random chance of being either a 0 or a 2 (assuming 2's can be adjacent to each other). So something like this should also be enough:

(repeatedly 10 #({0 0 1 2} (rand-int 2)))
;; => (0 2 0 2 0 2 0 0 0 0)


or maybe even (repeatedly 10 #(rand-nth [0 2])) ? this way you have some control over the distribution of the numbers, e.g. you can say (repeatedly 10 #(rand-nth [0 0 2])) if you want to have "twice" as many 0s as 2s (twice doesn't really make sense here, i'm using it figuratively)


you might also look at test.check generators to make these kinds of things

💡 2

helpfully, spec makes them for you if you can describe the sequence


% clj -Sdeps '{:deps {org.clojure/test.check {:mvn/version "0.9.0"}}}'
Clojure 1.10.1
user=> (require '[clojure.spec.alpha :as s] '[clojure.spec.gen.alpha :as gen])
user=> (gen/sample (s/gen (s/+ (s/cat :a (s/* #{0}) :b #{2}))))
((2) (2 2) (2) (0 2 0 0 2 0 0 2 0 2) (0 2 0 2 0 0 0 0 2 0 0 0 0 2) (0 0 0 0 2 0 0 0 0 2 0 0 0 2 0 0 2) (0 0 0 0 0 2 0 2) (0 2 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 2) (0 0 0 0 0 2 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 2) (0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 2))

🤯 2
pavlosmelissinos17:04:53 > * - 0 or more of a predicate/pattern (check out the examples in the docs, they're really helpful)


Ah, like FSM notation. So + is "one or more" ? thank you i will check out the link


s/* => “Zero or more instances of” (like in regex)


Is there an easy way to parse a date string like this Fri, 02 Apr 2021 18:00:17 GMT into a date instance? I’ve tried with java.time.Instant/parse but didn’t work


DateTimeFormatter, in java time, will do that if you give it a pattern

👍 1

do you know how you ended up with that string?


Last-Modified header has a value like that, for example curl -I -X GET


oh bummer

((juxt #(get % "Date") #(get % "Last-Modified"))
                              (:headers (http/get "")))
["Fri, 02 Apr 2021 19:49:39 GMT" "Fri, 02 Apr 2021 18:00:17 GMT"]
was hoping those wouldn't be strings like that programatically.


in case someone else finds it useful, the way I achieved that:

(def t (.parse java.time.format.DateTimeFormatter/RFC_1123_DATE_TIME "Fri, 02 Apr 2021 18:00:17 GMT"))
(java.time.Instant/from t)


There's also an utility function in ring for parsing HTTP-header style dates:

(ring.util.time/parse-date "Fri, 02 Apr 2021 18:00:17 GMT")
;;=> #inst "2021-04-02T18:00:17.000-00:00"

🙏 1
Joseph Rollins20:04:18

maybe more of a spacemacs question... I have both the clojure layer and lsp layer enabled and when I open a new file I get the namespace autogenerated twice e.g.:

(ns my-ns)

(ns my-ns)
anyone know how I can disable 1 of these two from filling in the namespace?


Check *Conflict with clj-refactor when creating new files*

🙌 1
Joseph Rollins20:04:59

awesome, thanks!

👍 1

would anyone know how to include XML CDATA in a hiccup map? I am writing a babashka script that takes an edn file with markdown and turns it into an RSS feed. e.g.

  [:title "new post"]
  [:link ""]
   [:description (markdown->html "**some stuff**")]]


@webmaster601 according to the readme of

[:-cdata "not parsed <stuff"]


oh, my gosh, thank you!


Also, thank you for babashka. It is incredible!

❤️ 1