Fork me on GitHub
#beginners
<
2017-10-01
>
wilcov12:10:30

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)))

eggsyntax15:10:40

Probably too late to be of use, but I wanted to point out also that you’ve got count(chart) instead of (count chart).

wilcov17:10:29

Thanks, i noticed that as well. case of mixed up syntax hehe

eggsyntax20:10:18

I do the same thing in the other direction these days 😜

eggsyntax20:10:56

& 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.

wilcov08:10:51

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

rcustodio12:10:03

The recur should be inside the if (the else of it)

wilcov12:10:57

that makes sense actually, thanks!

rcustodio12:10:42

✌️:skin-tone-2:✌️:skin-tone-2:

mseddon18:10:08

Coming from CL, I wonder is there a way to something like macrolet or symbol macros?

mseddon18:10:07

oop. tools.macros, yay.

dfcarpenter23:10:49

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

Chris Bidler01:10:49

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?

Chris Bidler02:10:44

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")))))

Chris Bidler02:10:28

(styles 3 7) -> ["done" "done" "done" "doing" "todo" "todo" "todo" "todo" "todo"]