This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-01
Channels
- # beginners (15)
- # boot (3)
- # cider (10)
- # clara (2)
- # cljs-dev (19)
- # clojure (31)
- # clojure-uk (9)
- # clojurescript (60)
- # core-async (1)
- # datomic (10)
- # docs (4)
- # fulcro (5)
- # hoplon (33)
- # juxt (1)
- # luminus (1)
- # off-topic (3)
- # om (20)
- # parinfer (2)
- # portkey (61)
- # re-frame (6)
- # reagent (39)
- # shadow-cljs (18)
- # spacemacs (4)
- # specter (8)
I've just started learning clojure (for the nth time :p) and decided to try my hand at the adventofcode 2016 challenges. Now i'd like to use the recur functionality. However with my code it seems to keep looping, can anybody point me in the right direction?
(def chart ["L2" "L3"])
(loop [chart chart]
(if (= 1 count(chart)) (println chart))
(recur (rest chart)))
Probably too late to be of use, but I wanted to point out also that you’ve got count(chart)
instead of (count chart)
.
& congrats on giving clj another shot! Don't hesitate to ask for help here, people are super-friendly. Took me a couple of tries as well.
Yeah people are great here. I'm getting close to solving the first advent of code challenge and i've got a better understanding of loop / recur so i'm happy
I'm trying to translate a function from js to cljs and i'm struggling with converting the loop. I think i'm misunderstanding something fundamental about loop/recur. https://gist.github.com/dfcarpenter/06f3cd28223061acc7584159dcfcc0fb
So the goal here is to produce a sequence of style values where 0
to idx - 1
is done
, idx
is doing
, and the remainder are todo
?
I think this fn
does what you want:
(defn styles
"Build a vector of styles for the todo items"
[idx len]
(into []
(flatten
(conj
(repeat (- len (- idx 1)) "todo")
"doing"
(repeat idx "done")))))
(styles 3 7)
-> ["done" "done" "done" "doing" "todo" "todo" "todo" "todo" "todo"]