I'm trying to recursively append a list in clojure. It is to deconstruct a POW function that I created, turning (POW x 3) into (* x (* x x))
I'm a really novice Clojure programmer, and attempting to wrap my head around this problem in Clojure is kind of tough. I have come up with:
(defn do-it [x n]
(if (= n 0)
(println x)
((dec n) (if (= x 'x))
(list '* 'x 'x)
(list '* 'x x))))
Which will not compile or run, but that is where my plan is going. My idea is to decrease n every time you add another (* x to the list.
I have this, which is similar to what I'm trying to do, but does not implement the POW idea into the function:
(defn do-it [x]
(if (= x 'x)
(list '* 'x 'x)
(list '* 'x x)))
Am I on the right path with the first piece of code? Is what I'm trying even possible?
expressionorvalueof your result?