This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-22
Channels
- # beginners (20)
- # boot (5)
- # cider (14)
- # cljs-dev (15)
- # cljsrn (1)
- # clojure (81)
- # clojure-greece (7)
- # clojure-italy (17)
- # clojure-spec (5)
- # clojure-uk (15)
- # clojurescript (143)
- # data-science (1)
- # datomic (7)
- # defnpodcast (4)
- # docs (1)
- # figwheel-main (1)
- # fulcro (37)
- # graphql (1)
- # hoplon (3)
- # luminus (1)
- # reitit (5)
- # shadow-cljs (10)
- # spacemacs (5)
- # tools-deps (14)
- # vim (7)
@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?
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?
Not a clue, personally, but I’d suggest posting that one in #clojurescript and/or #re-frame. Good luck!
Happened to run across this today, dunno if it may be helpful: https://github.com/mobileink/lab.clj.webcomponents
@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))))
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
Your solution is probably more efficient (especially in the event that the result is large)
if I'm understanding Clojure correctly.. would that be because the solution you provided is stack consuming.. while loop/recur is not?
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
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))
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!
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
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
but style wise many would discourage using a macro like that inside a threading macro