Fork me on GitHub

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


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


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


& 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


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


that makes sense actually, thanks!




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


oop. tools.macros, yay.


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.

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 []
    (repeat (- len (- idx 1)) "todo")
    (repeat idx "done")))))

Chris Bidler02:10:28

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