Fork me on GitHub
Ar Nazeh07:08:38

Good morning everyone, 👋 I am a new developer who just got his first job working with JS. Thanks to Roam Research I got intrigued by Clojure and intend to explore it further, I struggled to find much Clojurians on Twitter so here I am, and would still love to follow you If you are active there!

👋 75

@ar.nazeh a warm welcome to you!

🙏 3
💯 6
Mark Gerard17:08:42

Hey, (+ (.-x p) (.-y p)) what is the best way to remove the p repetition? (+ (->> p (.-x) (.-y))) is failing for me


> (clojure.walk/macroexpand-all '(+ (->> p (.-x) (.-y))))
(+ (. (. p -x) -y))


I'm not sure there's a good way to get rid of the p repetition

Mark Gerard17:08:38

interesting -

Alex Miller (Clojure team)17:08:01

I don't think any answer to that is going to be more readable than what you have

Mark Gerard17:08:19

Thanks! Would love to see an alternative, if you have time to burn

Alex Miller (Clojure team)17:08:36

something like juxt is the typical way to apply multiple functions to the same piece of data

Alex Miller (Clojure team)17:08:50

but that's bad in multiple ways here

Alex Miller (Clojure team)17:08:14

it's way more verbose and it forces boxed numbers which is way slower

Alex Miller (Clojure team)17:08:44

(apply + ((juxt #(.-x %) #(.-y %)) p)) something like that

Alex Miller (Clojure team)17:08:14

don't be afraid of repetition


Could be a juxt-like macro

Alex Miller (Clojure team)17:08:43

then you have to understand the macro

Alex Miller (Clojure team)17:08:09

unless you have 10 attributes or something, this is losing in every dimension imo


repeated names are how you make a computational graph

Alex Miller (Clojure team)17:08:52

KISS > DRY every day :)

Mark Gerard17:08:36

Yeah, that juxt alternative above is not readable, unless we are being esoteric and obstructionist


I wouldn’t hate some kind of simple destructuring macro for this. But for this simple example I agree it’s overkill

Mark Gerard17:08:34

Well, I can maybe roll my own, because DSL 🙂


I'm building a Clojurescript frontend app and Clojure backed, I can run the frontend separately and the backend but I'm wondering how during dev I can just fire up one instance so that I can test frontend -> backend calls without having to hard code /port:path in the frontend


the browser's Location object, , has enough info to construct a path back to the host the webpage was served from.


May be my question wasn't very clear, in my re-frame app I make calls to my backend /api/users if I start the repl for the frontend and make those calls they will be mapped to the frontend server+port so but my backend http server is running on I could hard code the paths in the frontend, just wondering if there's another way, does this make sense?


What do you use as your frontend server?


you could pass the api end point to the frontend. there's a couple of different ways to do that. the most straight forward is to just dynamically add a script tag like:



@UM72P2SQM if it's shadow-cljs, then you're probably looking for this:

👍 3

What I do is have my backend, your localhost:8080 I believe, serve the static assets and thus, hits the correct endpoints by default. I’m using figwheel and still use that to serve up files updates. Apologies if this wasn’t what you were looking for, just thought I would through this out there.


How would you translate the following into a transducer-based solution, in a way that the map and filter is only executed once?

(->> [:foo :bar :baz]
     (map str/upper-case)
     (filter some?)
I came up with these, but both seem overly cumbersome. (The printlns are just to be able to count iterations.)
  (comp (map str/upper-case)
        (filter some?))
  (completing (fn
                ([] nil)
                ([result input]
                 (println "⇒" result input)
                 (reduced input))))
  [:foo :bar :baz])
(first (eduction (comp
                   (map str/upper-case)
                   (filter some?)
                   (fn [rf]
                       ([] (rf))
                       ([result] (rf result))
                       ([result input]
                        (println "⇒" result input)
                        (reduced (rf result input))))))
                 [:foo :bar :baz]))