Fork me on GitHub
#beginners
<
2020-08-14
>
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!

๐Ÿ‘‹ 25
agigao10:08:35

@ar.nazeh a warm welcome to you!

๐Ÿ™ 1
๐Ÿ’ฏ 2
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

phronmophobic17:08:20

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

phronmophobic17:08:09

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

Mark Gerard17:08:38

interesting -

alexmiller17: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

alexmiller17:08:36

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

alexmiller17:08:50

but that's bad in multiple ways here

alexmiller17:08:14

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

alexmiller17:08:44

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

alexmiller17:08:14

don't be afraid of repetition

delaguardo17:08:30

Could be a juxt-like macro

alexmiller17:08:43

then you have to understand the macro

alexmiller17:08:09

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

hiredman17:08:51

repeated names are how you make a computational graph

alexmiller17: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

dpsutton17:08:37

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 ๐Ÿ™‚

subsaharancoder21:08:47

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

phronmophobic21:08:31

the browser's Location object, https://developer.mozilla.org/en-US/docs/Web/API/Location , has enough info to construct a path back to the host the webpage was served from.

subsaharancoder21:08:11

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?

jsn22:08:25

What do you use as your frontend server?

phronmophobic22:08:29

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:

<script>window.MY_API_ENDPOINT="";</script>

jsn22:08:51

@UM72P2SQM if it's shadow-cljs, then you're probably looking for this: https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http-proxy

๐Ÿ‘ 1
athomasoriginal00:08:14

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.

walterl23:08:59

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?)
     first)
I came up with these, but both seem overly cumbersome. (The printlns are just to be able to count iterations.)
(transduce
  (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]
                     (fn
                       ([] (rf))
                       ([result] (rf result))
                       ([result input]
                        (println "โ‡’" result input)
                        (reduced (rf result input))))))
                 [:foo :bar :baz]))