;; Version 1: direct inline the anonymous function:
(defn as-currency
"Money amounts are transmitted as \\"$2.44\\".
Parse this and return a numeric type."
[currency-amount]
(-> (subs currency-amount 1)
((fn [x] (println x) x))
(bigdec)
((fn [x] (println x) x))))
;; Version 2: use the inspect function described earlier:
(defn inspect
"Print out a value for debugging. Optional arguments are appended for
information."
([val]
(println val)
val)
([val & msgs]
(println val (str/join " " (cons "--" msgs)))
val))
(defn as-currency
"Money amounts are transmitted as \\"$2.44\\".
Parse this and return a numeric type."
[currency-amount]
(-> (subs currency-amount 1)
(inspect "stripped")
(bigdec)
(inspect "as bigdec")))
;;;; Evaluating the sample code prints the following:
;; 1200.20 -- stripped
;; 1200.20M -- as bigdec
;; 0.03 -- stripped
;; 0.03M -- as bigdec
;; 120.00 -- stripped
;; 120.00M -- as bigdec
;; 5.99 -- stripped
;; 5.99M -- as bigdec
;; 20 -- stripped
;; 20M -- as bigdec
;; 12.33 -- stripped
;; 12.33M -- as bigdec
;; $4.50 -- stripped
;; NumberFormatException java.math.BigDecimal.<init> (BigDecimal.java:494)