Hi Base,

It's useful to think of the "pattern" of loop/recur and then  apply it
to your problem. I.e

(loop [-- initial bindings --]
  (if --- terminating condition ---
     ---return result---    ; otherwise...
    (do-stuff with bindings
        (recur ---with new bindings---))))

A simple example first; find (gather all ints in a vector larger than
some given int...

(defn gather-ints
  [x coll-ints]
  (loop [s-ints (seq coll-ints) v-out []]
    (if (nil? s-ints) v-out
      (let [i (first s-ints)
            v-out (if (> i x) (conj v-out i) v-out)]
        (recur (next s-ints) v-out)))))

(gather-ints 3 [1 2 3 4 5 6])
=> [4 5 6]

Note that you can access all bindings in lexical scope, e.g x. Also
see how v-out is reused (like a variable, but its not - its just the
name rebound to a new value. We use seq of the collection which
returns either nil or a sequable to which you use next for the next
item. This is idiomatic for clojure for loop/recur.

Now for your problem;

(defn date-seq
  [d1 d2]
  (loop [b (-> d1 (.dayOfMonth)
             (.withMinimumValue))
         v-out [] ]
    (if (time/before? b e)
      (recur (.plusMonths b 1) (conj v-out b))
      v-out)))

-Hth, Adrian.

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

Reply via email to