siyu798 writes:
Hi Siyu,
> Your with-default fn is neat. So it appears there's no
> idiomatic/built-in clojure fn/macro to do parsing and wrapper
> functions such as follow would be needed to avoid typing the whole
> expression every time.
>
> (def parse-double (with-default #(Double. %) 0.
Tassilo and Alan,
Thanks for responding. We're new to clj and don't have a good feel of
when to you use macros over functions.
(defmacro with-dflt
"Runs body in a try/catch returning result of body
if no exception otherwise default"
[default & body]
`(try
(do ~@body)
(catch Ex
Alan,
Your with-default fn is neat. So it appears there's no
idiomatic/built-in clojure fn/macro to do parsing and wrapper functions such
as follow would be needed to avoid typing the whole expression every time.
(def parse-double (with-default #(Double. %) 0.0))
(def parse-int (with-defaul
On Jul 25, 1:18 pm, siyu798 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-de
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 received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to
siyu798 writes:
Hi!
>Is there an idiomatic/built-in way to parse double with a default
> value if there's exception?
Not that I know of.
> Currently we use a generic with-default macro to ignore exception and
> return default value as follow:
>
> (with-default 0.0 (Double. my-value))
Why
Hi,
Is there an idiomatic/built-in way to parse double with a default value
if there's exception? Currently we use a generic with-default macro to
ignore exception and return default value as follow:
(with-default 0.0 (Double. my-value))
--
You received this message because you are subscri