document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. ;; From e.g. https://github.com/scottjad/uteal
  2. (defmacro dlet
  3.   "let with inspected bindings"
  4.   [bindings & body]
  5.   `(let [~@(mapcat (fn [[n v]]
  6.                      (if (or (vector? n) (map? n))
  7.                        [n v]
  8.                        [n v \'_ `(println (name \'~n) ":" ~v)]))
  9.                    (partition 2 bindings))]
  10.      ~@body))
  11.  
  12. (defn as-currency
  13.   "Money amounts are transmitted as \\"$2.44\\".
  14.  Parse this and return a numeric type."
  15.   [currency-amount]
  16.   ;; strip off the leading "$"
  17.   (dlet [stripped (subs currency-amount 1)
  18.          decimal (bigdec stripped)]
  19.         decimal))
  20.  
  21. ;;;; Re-evaluating the sample calculation gives us this:
  22.  
  23. ;; stripped : 1200.20
  24. ;; decimal : 1200.20M
  25. ;; stripped : 0.03
  26. ;; decimal : 0.03M
  27. ;; stripped : 120.00
  28. ;; decimal : 120.00M
  29. ;; stripped : 5.99
  30. ;; decimal : 5.99M
  31. ;; stripped : 20
  32. ;; decimal : 20M
  33. ;; stripped : 12.33
  34. ;; decimal : 12.33M
  35. ;; stripped : $4.50
  36. ;; NumberFormatException   java.math.BigDecimal.<init> (BigDecimal.java:494)
');