Fork me on GitHub
#beginners
<
2018-07-22
>
fmn03:07:49

Anybody has a recipe on how to compose com.stuartsierra.component's in a clean way?

jonahbenton12:07:41

@funyako.funyao156 Components can be a solution to a problem, though there may be other solutions as well. What do you see as the problem you're facing?

Jp Soares12:07:06

Is anyone using http://www.webcomponents.org with clojurescript? I tested importing one component and it seems that different components might need different ways to import. Are there some known issues or tips for using them with re-frame?

eggsyntax02:07:52

Not a clue, personally, but I’d suggest posting that one in #clojurescript and/or #re-frame. Good luck!

Jp Soares10:07:26

Yeah.. I posted in #clojurescript, but no answer 😞 I'll try re-frame, thanks.

eggsyntax00:07:32

Happened to run across this today, dunno if it may be helpful: https://github.com/mobileink/lab.clj.webcomponents

mfikes18:07:10

@ryan.russell011 iterate is interesting, given you’ve defined calculate-next-val. Cobbling together a naive solution based on that

(defn collatz' [n] (count (take-while #(> % 1) (iterate calculate-next-val n))))

_rj_r_18:07:45

that is much more of a functional approach than my original. Now I'm mad I didn't think of that lol. I've used all those components before.... Sometimes my brain clicks into being functional..and other times I super struggle to approach things in a functional way and default to my damn imperative habits ... grrrrr

mfikes18:07:40

Your solution is probably more efficient (especially in the event that the result is large)

_rj_r_18:07:31

if I'm understanding Clojure correctly.. would that be because the solution you provided is stack consuming.. while loop/recur is not?

mfikes18:07:17

Nah… the main concern with the (count (take-while ... approach is that it will actually produce and hold a sequence in memory, and then count it

mfikes18:07:52

(collatz' 989345275647) will create a sequence of length 1348

mfikes18:07:58

Well, actually, because of locals clearing count won’t actually hold it in RAM

mfikes18:07:53

An intermediate step, which uses iterate and parts of your solution is

(defn collatz'' [num]
  (reduce (fn [count n]
            (if (>= 1 n)
              (reduced count)
              (inc count)))
  0
  (iterate calculate-next-val num))

mfikes18:07:10

(That one performs a lot like your raw loop/recur approach)

_rj_r_19:07:20

I like that solution. Whenever I see a loop/recur situation, my brain goes to reduce, and I couldn't figure out how to make that work with this problem. Thank you.. that was very help in seeing a few different alternatives to how I approached this problem!

_rj_r_19:07:26

is the usage of cond in my original solution idiomatic?

colinkahn19:07:54

Are there any tricks to using set! with the threading macros? Right now I'm using as-> but curious if it can work with the thread-first macros or doto

noisesmith19:07:37

set! is a macro which doesn't evaluate the first arg, so it won't work with many useful instances of thread-first or doto, but it can reasonably be used with thread-last

noisesmith19:07:02

but style wise many would discourage using a macro like that inside a threading macro

👍 8