Fork me on GitHub
Adam Kalisz00:12:27

Is it possible, to have some side-effecty thing as a binding in a doseq and still doing side effects in the body? Like this:

(doseq [x (range 0 3)
        _ (log/info "LOG" x)
        y ["a" "b" "c"]]
  (spit "test_doseq.txt" [x y] :append true))


change _ (log/info ...) to :let [_ (log/info ...)]

👍 1

the problem is that you aren't consuming _


doseq is a big weird macro, it has a lot of counterintuitive corner cases, inevitably

Adam Kalisz00:12:26

Great, it works! Yes, it is perhaps better to just have the other doseq inside the body for readability. Thank you for your time.

Adam Kalisz00:12:09

It seems to only do the first side-effect here. I want to log something only when x is different than the previous one without embedding another doseq in the body just so I can have a log.


(defn add-submap [m new-key new-keys-value]
   (fn [acc k v]
     (assoc acc k (assoc v new-key new-keys-value)))
=> (add-submap {:a {:b 1} :c {:d 2} :e {:f 3}} :email-verified nil) => {:a {:b 1, :email-verified nil}, :c {:d 2, :email-verified nil}, :e {:f 3, :email-verified nil}}


took me a little while to wrap my head around what was going on, but it was satisfying to figure out! 😃


Does anyone know of a good resource (books, talks on YouTube, blog posts, etc.) which provide a high-level overview of best practices and libraries for “full-stack web development” using Clojure (back-end) and ClojureScript (front-end)? I’m looking for a resource to give me the “lay of the land,” so to speak. A bit more context: Coming from a background of using “language/framework pairs” such as PHP/Laravel, Python/Django, Ruby/Rails and Elixir/Phoenix—I’m struggling with the fact that, with Clojure, the recommended approach is to compose various libraries, such as Ring, Compojure, Reitit, Pedestal, Re-agent, Re-frame, Hiccup, Garden, etc. I see there are also some “higher-level libraries,” such as Luminus and Fulcro. I’m searching for something that will teach me how to choose and compose the “right” libraries, in lieu of a framework. Note that I have already purchased a copy of “,” which I’m hoping will be a good starting points. From skimming through the table of contents and reviews, it seems to be focused on Luminus. (?) I’m looking forward to working through that book during my upcoming Christmas vacation.


Hi! Here is a good resource:


Also, the parent


I've heard good things about too


see #fulcro


I think this is a good introduction to fullstack clojure webdev


Thanks, @UBRV1HXPD! I purchased that book a few weeks ago, and I’m planning to read it over the Christmas holidays.

👍 1

I'm gonna say Compojure with Ring on the backend Rum via Shadowcljs on the frontend mix and match static and js however you need Selmer for templating html


Pedestal on the backend is also good for routing / middleware (instead of Ring)


Thanks for the tips, @U3ES97LAC!


I am trying to more aware of how i setup my functions, and I maybe got to a state where i overthink it waay to much. This is a very basic example, but even here I have doubts: I have a validation function that validates an object in an s3 bucket. This function needs to verify that a virus-scan-status is clean as well as a bunch of other stuff. Let me use the virus scanning as example.

(defn is-virus-scan-clean? [s3-client s3-bucket-name s3-key]
  "Returns true if the virus scan is clean"
  (let [scan-status (get-virus-scan-status! s3-client s3-bucket-name s3-key)]
    (= "CLEAN" scan-status)))

(defn is-virus-scan-clean2? [scan-status]
  (= "CLEAN" scan-status)) 

(defn validate-s3-object [s3-client s3-bucket-name s3-key]
    {:virus-clean? (is-virus-scan-clean2? (is-virus-scan-clean? s3-client s3-bucket-name s3-key))})

(defn validate-s3-object2 [s3-client s3-bucket-name s3-key]
  (let [scan-status (get-virus-scan-status! s3-client s3-bucket-name s3-key)]
    {:virus-clean? (is-virus-scan-clean2? scan-status)}))
Here i have 2 functions. Function1 first fetches the relevant scan-status inside the is-virus-scan-clean? function. This i currently find the best, however, it is not very pure. I also find it weird that i parse in a bunch of s3-info stuff to this function. Function2 receives the scan-status as input and therefore the function itself is pure. However it doesn't seem like there is much i gain from this function being pure. However i like that this function does not need any s3-info stuff to perform this action. Maybe there is no correct answer, but i would like to hear what people think about this


I prefer the second approach, since (as you've mentioned) it leads to more pure functions. Also, the first approach violates the single responsibility principle: it fetches the status and checks it.


Style side note: predicate function names are better without is- prefixes.


The benefit of the second, "more pure functions" approach isn't as clear in a tiny example like this, but pure functions are generally easier to reason about and test.


Maximizing for function purity also has the positive side effect of pushing side effects closer to the boundaries of your program, isolating it to some known subset of your code base.


(I forget which book/article I learned that from, but it was a pretty profound realization. In the book/article the author was building up an RDD solution to a problem, continuously refactoring the working code to factor out pure functions. It was beautiful to see it applied and what the results are. wow)


That makes sense. Sounds very interesting. If you find out the name of the book/article please let me know!

👍 1

I think it might have been this talk: by Rafal Dittwald

🙌 1

It's pretty great either way 🙂


The of that video also has some relevant discussion. The more common phrase "pushing side-effects to the system edges" is used there, as well as "functional core, imperative shell", which is often referenced.

🙌 1

So bascially its a question if its better to group all the sideeffects to wind up in the outer validation function to then go on calling a bunch of pure functions. Or if its better to call the function with sideeffects in the function that needs the result of said sideffect

Jelle Licht11:12:40

Is there a clojure spec (1) way to easily specify N (hardcoded) repeats of something? Or just s/cat and hardcode :entry1, :entry2, :entry3…?

Jelle Licht11:12:15

As a simple example: how would you spec a tic-tac-toe game field, as a vec of vecs (3x3)?


spec/coll-of has :count and :kind parameters, which I think would get you what you're looking for.

Jelle Licht13:12:57

picard-facepalm I can't believe I missed that. Thanks!

👍 1
Jelle Licht13:12:28

Another spec question: is there an spec for an interposed string? E.g. conforming “hello,hello,hello,hello” with as relevant elements the string ”hello” and character \,


regular expression will be my 2 bits of suggestion...

Jelle Licht13:12:57

Fair enough. I was hoping to be able to compose specs here, as instead of ”hello” I might have stricter requirements on my repeating element.

Alex Miller (Clojure team)13:12:10

Nothing built in for that


It technically still uses regex, but you could use the string library's split method with separator #"hello" and then validate the remaining strings via spec/coll-of.


What is the difference between on-change and value here ?

(defn page [ratom]
      "Please enter your name: "
      [:input {;:on-change #(swap! ratom %)
               :on-change (fn [evt]
                             (reset! ratom (-> evt .-target .-value)))
               :value @ratom}]]
    [:p "Your name is " @ratom]])


value is what the contents of the input field will be when that part of the page is rendered. on-change describes an event that is fired when you edit the contents of the input field (sort of) This has nothing to do with clojure or clojurescript btw.


ohh! got it thanks


Is their a way to set in my REPL max recursion depth ?


Are you using recur ? That affects the recursion depth.


I am, but my code has a problem I can't find that means I'm not terminating the recursion properly so it goes on forever, was hoping to set it to a low number so instead of going on forever it just stops after n recurs


what's your editor? nevermind, I misread the question


VS Code and Calva


I know there is INteruppt running evaluation, but for reasons I dont understand sometimes it doesnt stop and I have to kill the repl altogether


I think because maybe I'm using 100% CPU


@U11BV7MTK’s answer in using:

extra parameter (often called "gas")

👍 1


(loop [my-counter 0
       [h & t]    some-list]
  (if (= my-counter 10)
      (recur (int my-counter) t)))


funny enough, int is obviously a typo but would not error :D


(it would just quietly do the wrong thing)

😂 2

hey there stranger! been a while since I’ve had a code review from ya

😆 1

Are you trying to increase that limit or lower it? From some quick reading, it looks like the jvm doesn’t expose this directly, but you can influence it by setting the stack size for the jvm


I'm using recur, but I'm debugging an issue in my code where i'm not terminating the recursion as I think I am. So it goes on forever, and sometimes I'm having to kill the repl. I was just wondering if I could maybe set it to 20-30 or something


ah. i was assuming actual calling the function style recursion rather than looping. In this case you are in complete control of the control flow. Add an extra parameter (often called “gas”) and throw an error when it is above some threshold


ah ok, i guess i could do something like

(loop [stuff, more stuff, x]
   (if (= x 10)
   (recur ojdfp djsdo (inc x))


I'm happy that I'm not the only person who has this issue!


another good trick is (when (zero? (mod x 100)) (println ....))


just to figure out why it isn't stopping


I typically use CIDER’s debugger so I can inspect variables and see how they are evolving. That’s the quickest way to figure out a runaway recursion in my experience. But that might not be part of the beginner class.