My take is almost identical but I used the same length arguments for
the collections which means that the difference in the if branch are
easier to spot, at the cost of more cryptic argument names. This
version will not blow the stack, and its easy to wrap in lazy-seq.

(defn nil-coalesce [s1 s2]
   (if (seq s1)
     (if (first s1)
       (cons (first s1) (nil-coalesce (rest s1) s2))
       (cons (first s2) (nil-coalesce (rest s1) (rest s2))))))


On 17 Aug, 15:07, Meikel Brandmeyer <m...@kotka.de> wrote:
> Yeah! Golf!
>
> user=> (defn nil-coalesce
>          [coll replacements]
>          (lazy-seq
>            (when-let [s (seq coll)]
>              (let [fst (first s)]
>                (if (nil? fst)
>                  (cons (first replacements)
>                        (nil-coalesce (rest s) (rest replacements)))
>                  (cons fst (nil-coalesce (rest s) replacements)))))))
> #'user/nil-coalesce
> user=> (nil-coalesce [nil 1 2 3 nil nil] [4 5])
> (4 1 2 3 5 nil)
>
> Sincerely
> Meikel

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