On Jul 25, 1:18 pm, siyu798 <siyu...@gmail.com> wrote:
> Tassilo,
>    The reason a generic default macro being used here is because we can use
> the same macro to parse other data type like integer:
>
> (with-default 1 (Integer. my-value))
>
> Thanks,
> siyu

You can still do the same with a function:

(defn with-default [f & [default]]
  (fn [& args]
    (try (apply f args)
         (catch Throwable _ default))))

(map (with-default #(Integer/parseInt %) 0)
     ["4" "test"])

;=> (4 0)

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