Re: Parsing double with default value

2011-07-25 Thread Tassilo Horn
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.

Re: Parsing double with default value

2011-07-25 Thread Michael
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

Re: Parsing double with default value

2011-07-25 Thread siyu798
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

Re: Parsing double with default value

2011-07-25 Thread Alan Malloy
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

Re: Parsing double with default value

2011-07-25 Thread siyu798
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

Re: Parsing double with default value

2011-07-25 Thread Tassilo Horn
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

Parsing double with default value

2011-07-25 Thread siyu798
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