The issue is (add1 (add1 [x])) is malformed: you probably mean (add1 (add1 x)).

An addn function could be implemented with iterate:

(defn addn [n x]
  (nth (iterate add1 x) n))


> On Nov 10, 2016, at 06:51, 'Rickesh Bedia' via Clojure 
> <clojure@googlegroups.com> wrote:
> 
> I have this function:
> (defn add1 [x]
>     (+ 1 x))
> which is just a very simple function that adds 1.
> 
> I now want to create a new function called add2 that uses add1 twice.
> I have tried
> (defn add2 [x]
>     (add1 (add1 [x]))
> but this doesn't work. (Can someone explain why this doesn't work. I think 
> its maybe I am calling the function incorrectly)
> 
> I have ideas about using recur because I eventually want to create a function 
> addn where the function takes arguments n and x and calls add1 n times to x
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> <http://groups.google.com/group/clojure?hl=en>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to