> I don't understand how loop works.
>
> (defn lo [x]
> (loop [y 0 x 1]
> (pr y)))
> user=> #'user/lo
> user=> (lo 5)
> 0nil
> user=>
>
>
> what exactly does loop var var var var mean?
'loop' is a binding form like 'let' that also serves as one of the
"jump to" locations for 'recur'. Your example bound y to 0 and x to 1
and then printed y.
> how would I do:
> loop var from 1 to 20, increment by 2
> print var
Here are a few of ways to accomplish the loop you gave:
(defn loop1 []
(loop [i 1]
(when (< i 20)
(pr i)
(recur (+ 2 i)))))
(defn loop2 []
(dorun (for [i (range 1 20 2)]
(pr i))))
(defn loop3 []
(doseq i (range 1 20 2)
(pr i)))
> Sdenote: the API-reference is great but it would be even better if
> there were examples. One example says more than a thousand words.
> Is there a way to contribute to that?
It's possible to contribute to that on the wiki:
http://en.wikibooks.org/wiki/Clojure_Programming#Examples
Feel free to add a new section with API examples or look around for a
place they might already fit in. I'm sure any contributions to the
wiki will be much appreciated.
--Steve